> The full, future-proof solution is something like this: > > (map #(let [n (Integer/parseInt % 16)] (short (if (bit-test n 15) > (bit-or n -65536) (bit-and n 65535)))) ["ff43" "0032"])
(-189 50) But if numbers should default to positive but not be coerced to negative, e.g., a -189 just for (short -0xBD) this might work, using nil for out of range values: (map #(try (Short/parseShort % 16) (catch Throwable t nil)) ["ff43" "- bd" "0032"]) > On a related note: if I have the symbol for a type, like "short" or > "int" or "byte", is there a way to ask Clojure what size word that > represents? I don't know if there's anything predefined, but you can always fall back to using (Short/MIN_VALUE), (Short/MAX_VALUE), etc. -- 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, reply using "remove me" as the subject.