I am working with a sequence of hex numbers that are in string format,
e.g.
("0x34" "0xff" "0x01" ...)
Is there a function for converting these strings into normal hex or
numbers?? I tried num, but it didn't work.
Thanks!
user=> (read-string "0x44")
68
Safer:
(defn hex->num [#^String s]
(binding [*read-eval* false]
(let [n (read-string s)]
(when (number? n)
n))))
You could also use parseInt, which will be faster, so long as you can
guarantee the format:
(defn hex->num [#^String s]
(Integer/parseInt (.substring s 2) 16))
Luc
Sent from my iPod
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient
> with your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
> To unsubscribe from this group, send email to clojure
> +unsubscribegooglegroups.com or reply to this email with the words
> "REMOVE ME" as the subject.