> I can't understand how the following code works.
> If I have a signed byte = -1 (1111 1111) and I logical-AND with 0xFF
[quoted text clipped - 15 lines]
> }
> }
There's no byte arithmetic: the operands are promoted to `int` if
necessary. So the 0xff value that's left is an int value -- 255.

Signature
Chris "congratulations on your promotion, Short!" Dollin
Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England
> Hello,
>
[quoted text clipped - 17 lines]
> }
> }
a & 0xFF is an int expression, computed by converting a to int, then
doing the operation in 32 bit int arithmetic.
0xFF is int so it would be done that way even if Java supported byte
arithmetic. However, even if you add two byte expressions, it is done by
converting both to int and the result is int.
See the JLS, "5.6.2 Binary Numeric Promotion",
http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#170983
Patricia
Philipp - 20 Nov 2007 16:45 GMT
> See the JLS, "5.6.2 Binary Numeric Promotion",
> http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#170983
Thanks...
Phil