home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / dev / obero / oberon-a / source / misc / hexconvert.mod < prev    next >
Encoding:
Text File  |  1994-08-08  |  2.0 KB  |  73 lines

  1. (*************************************************************************
  2.  
  3.      $RCSfile: HexConvert.mod $
  4.   Description: A little utility to convert unsigned hex integers to their
  5.                signed equivalents.
  6.  
  7.    Created by: fjc (Frank Copeland)
  8.     $Revision: 1.1 $
  9.       $Author: fjc $
  10.         $Date: 1994/06/09 14:29:51 $
  11.  
  12.   Log entries are at the end of the file.
  13.  
  14. *************************************************************************)
  15.  
  16. MODULE HexConvert;
  17.  
  18. (*$P-*)
  19.  
  20. IMPORT SYS := SYSTEM, IO := StdIO;
  21.  
  22. CONST
  23.   VersionTag = "\0$VER: HexConvert 1.0 (7.6.94)\r\n";
  24.   VersionStr = "HexConvert 1.0 (7 Jun 1994)\r\n";
  25.   CopyrightStr = "Written by Frank Copeland\n";
  26.  
  27. VAR
  28.   i, j, k : INTEGER; temp : LONGINT; ch : CHAR; digit : ARRAY 17 OF CHAR;
  29.  
  30. BEGIN (* HexConvert *)
  31.   IO.WriteStr (VersionStr);
  32.   IO.WriteStr (CopyrightStr);
  33.   IO.WriteLn ();
  34.   digit := "0123456789ABCDEF";
  35.   LOOP
  36.     i := 0; temp := 0;
  37.     IO.WriteStr ("Enter a hex integer => ");
  38.     LOOP
  39.       IO.Read (ch); IF ch = "\n" THEN EXIT END;
  40.       ch := CAP (ch); INC (i);
  41.       IF (ch >= "0") & (ch <= "9") THEN
  42.         k := ORD (ch) - ORD ("0")
  43.       ELSIF (ch >= "A") & (ch <= "F") THEN
  44.         k := ORD (ch) - (ORD ("A") - 10)
  45.       ELSE
  46.         IO.WriteStr ("\n !! Illegal hex digit\n"); temp := -1; EXIT
  47.       END;
  48.       IF i < 5 THEN temp := temp * 16 + k END
  49.     END;
  50.     IF i = 0 THEN
  51.       EXIT
  52.     ELSIF i > 4 THEN
  53.       IO.WriteStr ("\n !! Number is too big\n"); temp := -1
  54.     END;
  55.     IF temp >= 0 THEN
  56.       IF temp > 32767 THEN DEC (temp, 65536) END;
  57.       IO.WriteStr (" >> Signed equivalent : ");
  58.       IF temp < 0 THEN IO.Write ("-"); temp := ABS (temp) END;
  59.       IO.WriteHex (temp); IO.WriteLn ()
  60.     END;
  61.   END;
  62.   IO.WriteStr ("\nAll finished\n");
  63. END HexConvert.
  64.  
  65. (*************************************************************************
  66.  
  67.   $Log: HexConvert.mod $
  68. # Revision 1.1  1994/06/09  14:29:51  fjc
  69. # Initial revision
  70. #
  71. *************************************************************************)
  72.  
  73.