home *** CD-ROM | disk | FTP | other *** search
- -----------------------------------------------------------------------------
- --AsciiDmp.upl
- --Program to dump Decimal and Hexadecimal equivalents of Ascii Characters
-
- --The resulting file may require an advanced text editor to display it.
- --This program demonstrates file IO.
- -----------------------------------------------------------------------------
-
- group
- integer HexTable(16)--This table holds the ASCII values of the
- end group --hexadecimal digits. It is used to look up
- --the equivalent hexadecimal digit for a given
- --decimal number between 1 and 16.
-
- proc InitializeHexTable
-
- HexTable(1) = 48
- HexTable(2) = 49
- HexTable(3) = 50
- HexTable(4) = 51
- HexTable(5) = 52
- HexTable(6) = 53
- HexTable(7) = 54
- HexTable(8) = 55
- HexTable(9) = 56
- HexTable(10) = 57
- HexTable(11) = 65
- HexTable(12) = 66
- HexTable(13) = 67
- HexTable(14) = 68
- HexTable(15) = 69
- HexTable(16) = 70
-
- end proc
-
-
- --This function converts a decimal value between 1 and 255 and converts it
- --to an equivalent hexadecinal value. The hexadecimal value is returned as
- --a string of 2 characters
-
- func Hex(in integer Decval) return string
- integer Sixteens, Ones
- string FirstHexDig:1, SecondHexDig:1
-
- Sixteens = DecVal/16
- Ones = ModI(DecVal,16)
-
- FirstHexDig = Char(HexTable(Sixteens+1))
- SecondHexDig = Char(Hextable(Ones+1))
-
- if FirstHexDig = "0" then
- FirstHexDig = " "
- endif
-
- return FirstHexDig + SecondHexDig
-
- end func
-
-
-
- proc main
-
- integer i, charval = 2
- file f1
-
- print "initializing table....."
- InitializeHexTable
-
- print "Ready...."
-
- open f1 "asciidmp.dat"
- write f1
- write f1
- write f1, "Extended ASCII Codes"
- write f1
- write f1
- write f1, "Dec":8,"Hex":8,"Char":8, "Ctrl":8
- write f1
- loop i = 0 to 255
- write f1, i:7," ", Hex(i):7," ", Char(i):6," ",
- if (i<=31) then
- write f1, Char(i+64):6
- else
- write f1
- endif
- print ".",
- end loop
- write f1
- close f1
-
- print "Done"
-
- end proc
-