On Mar 24, 10:57 am, "Mark J. Reed" <[email protected]> wrote:
> On Tue, Mar 23, 2010 at 8:19 PM, Raph <[email protected]> wrote:
> > (My opinion, anyway.I think a byte should be 8 bits and I should be able to
> > use all of them.)
>
> Er, it is, and you can. A Java byte still gives you all 8 bits' worth
> of 256 different possible values; the interpretation of those values
> is all that differs here. Whereas C lets you pick between signed and
> unsigned (with the default unfortunately not always well-defined),
> Java gives you no choice but to use the signed interpretation. But
> you still get to use all 8 bits of the byte; it's just that the
> numbers mapped to [128, 255] in unsigned interpretations map to
> [-128,-1] instead.
Right, should have been more specific. The 0xFF byte doesn't work the
way I expect it to. I have to use ints to get the correct answer.
(bit-or (bit-shift-left (byte 0x01) 16)
(bit-shift-left (byte 0x7F) 8)) => 98048
(bit-or (bit-shift-left (int 0x01) 16)
(bit-shift-left (int 0x7F) 8)) => 98048
But...
(bit-or (bit-shift-left (byte 0x01) 16)
(bit-shift-left (byte 0xFF) 8)) => -256
(bit-or (bit-shift-left (int 0x01) 16)
(bit-shift-left (int 0xFF) 8)) => 130816
So I can't use the bits the way I'd expect.
Raph
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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.