What is the best way to work around the fact that ALL Java bytes are signed?

It is actually possible to get rid of the if statement and the addition if you do it like this.

byte[] foobar = ..;
int value = (foobar[10] & 0xff);

This way Java doesn’t interpret the byte as a negative number and flip the sign bit on the integer also.

Leave a Comment