论坛首页 入门技术论坛

Java读取Unsigned Int的程序

浏览 4420 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-12-09  

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);
    }

 

论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics