unsigned int的范围为0-4294967295
所以int不再适用,我们这里使用long型
程序如下
public static long readUnsignedInt(byte[] bytes) {
long b0 = ((long) (bytes[0] & 0xff));
long b1 = ((long) (bytes[1] & 0xff)) << 8;
long b2 = ((long) (bytes[2] & 0xff)) << 16;
long b3 = ((long) (bytes[3] & 0xff)) << 24;
return (long) (b0 | b1 | b2 | b3);
}
![]()
![]()
![]()
![]()
本文介绍如何将unsigned int类型的数据(范围0-4294967295)通过Java代码转换为long型。具体实现方法是通过位操作将四个字节的数据组合起来。
4948

被折叠的 条评论
为什么被折叠?



