开发者

how to read bytes bigger than 127 in java?

开发者 https://www.devze.com 2023-01-21 19:51 出处:网络
alright, so my code to read bytes into a int is like so: int offset = (byte << 16) |开发者_如何学运维 (byte2<< 8) | byte3;

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

精彩评论

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