Fork me on GitHub
#beginners
<
2015-09-23
>
stephen13:09:08

What's the best way to handle Bytes in Clojure?

stephen13:09:23

I got myself a byte : (byte 127)

stephen13:09:33

Which I then want to shift left

stephen13:09:01

So I go (bit-shift-left (byte 127) 1)

stephen13:09:33

But this returns an int - 254 - and not a byte.

stephen13:09:43

I wanna keep it as a byte.

stephen13:09:28

But I can't cast it back to byte cos I get a Value out of range for byte error.

stephen13:09:44

I quite happy to truncate any overflow.

stephen13:09:21

So I think maybe I can go (bit-and 0xff *1)

stephen13:09:39

But this doesn't work.

stephen13:09:08

Basically I want to have have an unsigned byte as opposed to a signed?

rauh13:09:21

@stephen: unchecked-byte should work

stephen13:09:35

@rauh: Awesome thanks. That does exactly what I want!

clojuregeek15:09:50

Figured out my problem with using reset in my repl, i ran lein clean yesterday I had aot in my project.cli and later removed it. I guess it left some stuff in classes that make it not be able to reload.

danielcompton22:09:38

@stephen: Java doesn’t really do unsigned bytes 😞