My wrote:
[...]
> when i got into the debug mode and ceck the variable, the value was
> -64 but the Hexadecimal value is (0xC0)

Java bytes are signed. The Eclipse debugger shouldn't be showing you the
value as 0xC0 --- that's incorrect; it should be giving you -40.

In order to get what you want, you need to convert the byte into an
integer and then truncate it down to an unsigned 8-bit value.

byte a = -64;
int b = ((int)a) & 0xFF;
assert(b == 0xC0);

All Java types are unsigned (except char). Yes, that's dumb.

-- 
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "I have always wished for my computer to be as easy to use as my
│ telephone; my wish has come true because I can no longer figure out
│ how to use my telephone." --- Bjarne Stroustrup

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to