home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OL.LZH / PROCS.LZH / HEXCVT.ICN < prev    next >
Text File  |  1991-07-13  |  967b  |  43 lines

  1. ############################################################################
  2. #
  3. #    Name:    hexcvt.icn
  4. #
  5. #    Title:    Hexadecimal conversion
  6. #
  7. #    Author:    Robert J. Alexander
  8. #
  9. #    Date:    November 8, 1990
  10. #
  11. ############################################################################
  12. #
  13. #  hex(s) -- Converts string of hex digits into an integer.
  14. #
  15. #
  16. #  hexstring(i) -- Returns a string that is the hexadecimal
  17. #  representation of the argument.
  18. #
  19. ############################################################################
  20.  
  21. procedure hex(s)
  22.    local a,c
  23.    a := 0
  24.    every c := !map(s) do
  25.      a := ior(find(c,"0123456789abcdef") - 1,ishift(a,4)) | fail
  26.    return a
  27. end
  28.  
  29. procedure hexstring(i,n)
  30.    local s
  31.    i := integer(i) | fail
  32.    if i = 0 then s := "0"
  33.    else {
  34.       s := ""
  35.       while i ~= 0 do {
  36.      s := "0123456789ABCDEF"[iand(i,15) + 1] || s
  37.      i := ishift(i,-4)
  38.      }
  39.       }
  40.    if \n > *s then s := right(s,n,"0")
  41.    return s
  42. end
  43.