home *** CD-ROM | disk | FTP | other *** search
- ############################################################################
- #
- # File: hexcvt.icn
- #
- # Subject: Procedures for hexadecimal conversion
- #
- # Author: Robert J. Alexander
- #
- # Date: November 8, 1990
- #
- ###########################################################################
- #
- # hex(s) -- Converts string of hex digits into an integer.
- #
- #
- # hexstring(i) -- Returns a string that is the hexadecimal
- # representation of the argument.
- #
- ############################################################################
-
- procedure hex(s)
- local a,c
- a := 0
- every c := !map(s) do
- a := ior(find(c,"0123456789abcdef") - 1,ishift(a,4)) | fail
- return a
- end
-
- procedure hexstring(i,n)
- local s
- i := integer(i) | fail
- if i = 0 then s := "0"
- else {
- s := ""
- while i ~= 0 do {
- s := "0123456789ABCDEF"[iand(i,15) + 1] || s
- i := ishift(i,-4)
- }
- }
- if \n > *s then s := right(s,n,"0")
- return s
- end
-