This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
Stephan van Hulst wrote:Just take an int, set it to 255 and then cast it to a byte. The cast will lop off the three high order bytes, leaving you with the byte value -1 (which is the same as 255 unsigned).
If you like, you can also do it without an intermediate variable.
The compiler will know what you mean, and calculate the int value of 255 casted to a byte, and do it at compile time.... ie. no three higher order bytes to lop off.