Re: formatting hex string

2010-03-31 Thread Mark J. Reed
On Thu, Apr 1, 2010 at 12:29 AM, Armando Blancas wrote: > 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: Yeah, but I was assuming (insert standard caveat here) that the goal is t

Re: formatting hex string

2010-03-31 Thread Armando Blancas
> 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 (shor

Re: formatting hex string

2010-03-31 Thread Mark J. Reed
On Wednesday, March 31, 2010, Richard Newman wrote: > > ur=> (map #(Integer/parseInt % 16) ["ff43" "0032"]) > (65347 50) > > > ...that yields ints, not shorts. > > > At the risk of diverging from the question: why are you concerned with the > specific type of the number? I am because the OP was.

Re: formatting hex string

2010-03-31 Thread Richard Newman
ur=> (map #(Integer/parseInt % 16) ["ff43" "0032"]) (65347 50) ...that yields, not shorts. At the risk of diverging from the question: why are you concerned with the specific type of the number? You realize that Java doesn't allocate less memory for a short than for an int, right? The on

Re: formatting hex string

2010-03-31 Thread Mark J. Reed
On Wed, Mar 31, 2010 at 7:22 PM, Glen Rubin wrote: > I have a sequence of hex strings, e.g. > > "ff43" "0032" ... (you get the idea) > > I want to use clojure's short form on them, but short expects an > authentic hex input, e.g. > > (short 0xff43) > > it will not accept something like (short "0xf

Re: formatting hex string

2010-03-31 Thread Richard Newman
"ff43" "0032" ... (you get the idea) I want to use clojure's short form on them, but short expects an authentic hex input, e.g. (short 0xff43) it will not accept something like (short "0xff43") Any suggestions would be gratefully appreciated!! user=> (map #(Integer/parseInt % 16) ["ff43" "00

formatting hex string

2010-03-31 Thread Glen Rubin
I have a sequence of hex strings, e.g. "ff43" "0032" ... (you get the idea) I want to use clojure's short form on them, but short expects an authentic hex input, e.g. (short 0xff43) it will not accept something like (short "0xff43") Any suggestions would be gratefully appreciated!! -- You re