Use a try catch around parseInt to report bad hex nb formats.
At least you'll know if you are feedind
odd values to your hex function.
Luc
Sent from my iPod
On 2010-03-27, at 5:18 PM, Glen Rubin <rubing...@gmail.com> wrote:
thanks...you rock!!
On Mar 27, 4:17 pm, Richard Newman <holyg...@gmail.com> wrote:
Is there a function for converting these strings into normal hex or
numbers?? I tried num, but it didn't work.
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))
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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.