home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p115 / 10.ddi / GCD4 / UPL / ASCIIDMP.UPL < prev    next >
Encoding:
Text File  |  1988-06-01  |  2.0 KB  |  95 lines

  1. -----------------------------------------------------------------------------
  2. --AsciiDmp.upl
  3. --Program to dump Decimal and Hexadecimal equivalents of Ascii Characters
  4.  
  5. --The resulting file may require an advanced text editor to display it.
  6. --This program demonstrates file IO.
  7. -----------------------------------------------------------------------------
  8.  
  9. group                     
  10.     integer HexTable(16)--This table holds the ASCII values of the
  11. end group                 --hexadecimal digits. It is used to look up
  12.                           --the equivalent hexadecimal digit for a given
  13.                           --decimal number between 1 and 16.
  14.  
  15. proc InitializeHexTable
  16.  
  17.      HexTable(1) = 48
  18.      HexTable(2) = 49
  19.      HexTable(3) = 50
  20.      HexTable(4) = 51
  21.      HexTable(5) = 52
  22.      HexTable(6) = 53
  23.      HexTable(7) = 54
  24.      HexTable(8) = 55
  25.      HexTable(9) = 56
  26.      HexTable(10) = 57
  27.      HexTable(11) = 65
  28.      HexTable(12) = 66
  29.      HexTable(13) = 67
  30.      HexTable(14) = 68
  31.      HexTable(15) = 69
  32.      HexTable(16) = 70
  33.  
  34. end proc
  35.  
  36.  
  37. --This function converts a decimal value between 1 and 255 and converts it
  38. --to an equivalent hexadecinal value. The hexadecimal value is returned as
  39. --a string of 2 characters
  40.  
  41. func Hex(in integer Decval) return string
  42. integer Sixteens, Ones
  43. string FirstHexDig:1, SecondHexDig:1
  44.  
  45.     Sixteens = DecVal/16
  46.     Ones = ModI(DecVal,16)
  47.  
  48.     FirstHexDig = Char(HexTable(Sixteens+1))
  49.     SecondHexDig = Char(Hextable(Ones+1))
  50.  
  51.     if FirstHexDig = "0" then
  52.         FirstHexDig = " "
  53.     endif
  54.  
  55.     return  FirstHexDig + SecondHexDig
  56.  
  57. end func
  58.  
  59.  
  60.  
  61. proc main
  62.  
  63. integer i, charval = 2
  64. file f1 
  65.  
  66.     print "initializing table....."
  67.     InitializeHexTable
  68.  
  69.     print "Ready...."
  70.  
  71.     open f1 "asciidmp.dat"
  72.     write f1
  73.     write f1
  74.     write f1, "Extended ASCII Codes"
  75.     write f1
  76.     write f1
  77.     write f1, "Dec":8,"Hex":8,"Char":8, "Ctrl":8
  78.     write f1
  79.     loop i = 0 to 255
  80.         write f1, i:7," ", Hex(i):7," ", Char(i):6,"  ",
  81.         if (i<=31) then
  82.             write f1, Char(i+64):6
  83.         else
  84.             write f1
  85.         endif
  86.         print ".",
  87.     end loop
  88.     write f1
  89.     close f1
  90.     
  91.     print "Done"
  92.  
  93. end proc
  94.  
  95.