美文网首页
字符数组化为整形

字符数组化为整形

作者: phi3 | 来源:发表于2017-07-19 16:24 被阅读0次

0xFF表示0000 0000 0000 0000 0000 0000 1111 1111

pulic static int bytesToInt(byte[] bytes){

int num=bytes[0] &0xFF;
//byte的8位和0xff进行&运算后,最低8位中,原来为1的还是1,原来为0的还是0,而0xff其他位都是0,所以&后仍然得0
//依次类推
num |=((bytes[1]<<8)&0xFF00);
num |=((bytes[2]<<16)&0xFF0000);
num |=((bytes[3]<<32)&0xFF000000);
return num;
}

相关文章

网友评论

      本文标题:字符数组化为整形

      本文链接:https://www.haomeiwen.com/subject/pqwlkxtx.html