开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜