Done:

https://www.assembla.com/spaces/clojure/tickets/284-cannot-cast-0xff-to-a-byte-(fails-out-of-range-check)

On Mar 24, 10:57 am, "Mark J. Reed" <markjr...@gmail.com> wrote:
> On Tue, Mar 23, 2010 at 8:19 PM, Raph <mart...@gmail.com> 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.
>
> The dissonance here comes from the fact that there's no real tradition
> of negative hexadecimal numbers in programming.  We've typically used
> the hexadecimal form of the unsigned integer interpretation to
> represent the corresponding bit patterns no matter how they're being
> used in a given program or context.  So anyone experienced with
> manipulating things at the bit level comes in expecting things like
> (byte 0xff) to just work, and is surprised when they don't.
>
> Still, the nice thing about Clojure vs Java is it's not hard to write a fix:
>
> (defmacro unsigned-byte [bval] (byte (if (> bval 127) (- bval 256) bval)))
>
> Or call it (ubyte) for less wordiness...
>
> --
> Mark J. Reed <markjr...@gmail.com>

-- 
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.

Reply via email to