home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / progtool / modula2 / lpr / conversi.def next >
Encoding:
Modula Definition  |  1994-09-22  |  2.2 KB  |  56 lines

  1. DEFINITION MODULE Conversions;
  2.  
  3.     PROCEDURE ConvertToString
  4.           (n : LONGCARD; b : CARDINAL; neg : BOOLEAN; 
  5.            VAR s : ARRAY OF CHAR; VAR done : BOOLEAN);
  6.  
  7.       (* n: number to convert.
  8.          b: base of converted string, (10=dec, 10H=16=hex etc)
  9.             2<=b<=36;
  10.          neg: if TRUE, the number is negative.
  11.          s: the resulting string, length(s)>=32.
  12.          done: if FALSE s is too short or b is not in the right range.
  13.          
  14.          eg.   ConvertToString(10,2,FALSE,s,done)
  15.          gives s = '1010'
  16.          
  17.                VAR x: INTEGER;
  18.                x:=-456;
  19.                ConvertToString(ABS(x),10,x<0,s,done)
  20.          gives s = '-456'                                   *)
  21.     
  22.     PROCEDURE ConvertFromString
  23.          (VAR s : ARRAY OF CHAR; b : CARDINAL; neg : BOOLEAN; 
  24.          max : LONGCARD; VAR result : LONGCARD; VAR done : BOOLEAN);
  25.            
  26.     (*   s: the string to convert.
  27.          b: the base of the string.
  28.          neg: TRUE => signed numbers are accepted.
  29.          max: the maximum number accepted.
  30.          result: the converted number.
  31.          done: TRUE => string OK & result OK, otherwise invalid caracter 
  32.                        in string eg. sign specified when signed number 
  33.                        not accepted, number too big etc.
  34.        
  35.          eg.   ConvertFromString('-123',10,TRUE,MAX(INTEGER),result,done)
  36.          gives result = -123, done = TRUE
  37.          
  38.                ConvertFromString('-123',10,FALSE,0FFFFH,result,done)
  39.                done = FALSE (sign not allowed)
  40.                
  41.                ConvertFromString('123',10H,FALSE,100,result,done)
  42.                done = FALSE (number too large)
  43.                
  44.                ConvertFromString('A5G',16,FALSE,MAX(CARDINAL),result,done)
  45.                done = FALSE (G is not a valid hex (base 16) character)
  46.                
  47.                ConvertFromString('+',10,TRUE,MAX(INTEGER),result,done)
  48.                done = FALSE (no number after the sign)                
  49.                
  50.  
  51.      Convertions between (LONG)REAL numbers and strings are provided in
  52.      the MODULE RealInOut                                              *)
  53.        
  54.  
  55. END Conversions.
  56.