how to read bytes bigger than 127 in java?
alright, so my code to read bytes into a int is like so:
int offset = (byte << 16) |开发者_如何学运维 (byte2 << 8) | byte3;
And it's reading the bytes "00 00 be" as -66.
How do I read it as the 190 it's meant to be?
byte b = -66;
int i = b & 0xff;
byte b = -66;
int i = b < 0 ? b + 256 : b;
It might be useful declare helper function for this.
精彩评论