In Java, char is unsigned -- it is essenitally unsigned short, but I think you really mean that byte in Java is signed, which is true, even though a byte that was unsigned would make mor sense for most uses of byte. The fix is simple: to convert a byte to an int value in the range [0,255] (ie, to treat a byte as unsigned) write:So your code could be written:That being said, check out DataInputSteam -- it may eliminate the need for doing this entirely! [ January 18, 2006: Message edited by: Jeff Albrechtsen ]
Originally posted by John McDonald: Hi Jeff, Thanks for a quick response. Is the return value a decimal value?
Technically, an int (or any data for that matter) is stored as binary. You should try compiling this code in a simple test framework and check if the int has the excpected decimal value that you would like for various byte inputs.
I arranged the bytes in that order because I was mimicking your code: Perhaps your question really is: which way are the bytes of a int stored? The answer is that it depends. Java prefers to store hi-order bytes first (big-endian).
Originally posted by Jeff Albrechtsen: It's an int. One doesn't speak of an int being a decimal or hex value because that doesn't make any sense. That's referring to the string format of a number. An int is an int.
...unless of course, you are legislating for the safety of hundreds of thousands of Australian road users. http://tmorris.net/pubs/md5-speed-cameras/ (second last paragraph)
You can concievably use either of these. The order of the bytes depends on whether the value is represented in big-endian or little-endian format. If you are interested, you should google for more information on these.
Originally posted by Tony Morris: ...unless of course, you are legislating for the safety of hundreds of thousands of Australian road users. http://tmorris.net/pubs/md5-speed-cameras/ (second last paragraph)
I knew that sooner or later too much Vegemite could cause some sort of brain damage But then again, it's not like they tried to legislate that PI be 3.2!
There is no emoticon for what I am feeling!
We don't have time to be charming! Quick, read this tiny ad:
a bit of art, as a gift, the permaculture playing cards