home *** CD-ROM | disk | FTP | other *** search
Modula Definition | 1994-09-22 | 2.2 KB | 56 lines |
- DEFINITION MODULE Conversions;
-
- PROCEDURE ConvertToString
- (n : LONGCARD; b : CARDINAL; neg : BOOLEAN;
- VAR s : ARRAY OF CHAR; VAR done : BOOLEAN);
-
- (* n: number to convert.
- b: base of converted string, (10=dec, 10H=16=hex etc)
- 2<=b<=36;
- neg: if TRUE, the number is negative.
- s: the resulting string, length(s)>=32.
- done: if FALSE s is too short or b is not in the right range.
-
- eg. ConvertToString(10,2,FALSE,s,done)
- gives s = '1010'
-
- VAR x: INTEGER;
- x:=-456;
- ConvertToString(ABS(x),10,x<0,s,done)
- gives s = '-456' *)
-
- PROCEDURE ConvertFromString
- (VAR s : ARRAY OF CHAR; b : CARDINAL; neg : BOOLEAN;
- max : LONGCARD; VAR result : LONGCARD; VAR done : BOOLEAN);
-
- (* s: the string to convert.
- b: the base of the string.
- neg: TRUE => signed numbers are accepted.
- max: the maximum number accepted.
- result: the converted number.
- done: TRUE => string OK & result OK, otherwise invalid caracter
- in string eg. sign specified when signed number
- not accepted, number too big etc.
-
- eg. ConvertFromString('-123',10,TRUE,MAX(INTEGER),result,done)
- gives result = -123, done = TRUE
-
- ConvertFromString('-123',10,FALSE,0FFFFH,result,done)
- done = FALSE (sign not allowed)
-
- ConvertFromString('123',10H,FALSE,100,result,done)
- done = FALSE (number too large)
-
- ConvertFromString('A5G',16,FALSE,MAX(CARDINAL),result,done)
- done = FALSE (G is not a valid hex (base 16) character)
-
- ConvertFromString('+',10,TRUE,MAX(INTEGER),result,done)
- done = FALSE (no number after the sign)
-
-
- Convertions between (LONG)REAL numbers and strings are provided in
- the MODULE RealInOut *)
-
-
- END Conversions.
-