Ahh, should've looked at the docs. Thanks for the helpful response. Travis
On May 8, 11:09 pm, "Stephen C. Gilardi" <squee...@mac.com> wrote: > On May 8, 2009, at 10:42 PM, tmountain wrote: > > > > > I'm working on a project that makes use of a lot of byte arrays, and > > I'm having an issue with certain bytes overflowing to negative values. > > I know they're being stored properly because I'm also generating hex > > dumps from time to time which indicate the real value is there. Can > > someone tell me how to go about making comparisons with the actual > > values? > > > user=> (byte 254) > > -2 > > > (def my-byte (make-array (Byte/TYPE) 1)) > > (aset my-byte 0 (byte 254)) > > (println (format-hex-string (HexByte/byteArrayToHexString my-byte))) > > ... returns "0xFE" ... > > > user=> (= (byte 254) 0xFE) > > false > > The byte type is always signed in Java. Its range is -128 to 127. > > It's documented here: > > http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Byte.html > > If you need to compare a byte to another value, one way is coerce both > to byte for the comparison: > > user=> (= (byte 254) (byte 0xFE)) > true > > --Steve > > smime.p7s > 3KViewDownload --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---