Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

int->hexstr and hexstr->int

// description of your code here

(set 'hextab "0123456789abcdef")

(define (int->hexstr num)
  (set 'hexstr "")
  (for (i 0 63 4)
       (push (hextab (& (>> num i) 0xf)) hexstr))
  (append "0x" hexstr))

(define (hexstr->int str)
  (set 'num 0)
  (set 'str (pop str 2))
  (for (i 0 15 1)
       (| (<< (find (str i) hextab) (* 4 i)) num)))


You need to create an account or log in to post comments to this site.


Click here to browse all 5140 code snippets