首页 > 编程语言 > 详细

Java无符号整形

时间:2020-11-27 19:29:15      阅读:33      评论:0      收藏:0      [点我收藏+]
/**
 * Created by Lovell on 7/7/16.
 */
public class UnsignedUtil {
    /**
     * java byte (1 byte == 8 bit) (-2^7~2^7-1 : -128~127) to unsigned short(0~2^8-1 : 0~255)
     *
     * @param data
     * @return
     */
    public static int getUnsignedByte (byte data){
        return data&0x0FF;
    }

    /**
     * java short (1 short == 2 byte == 16 bit) (-2^15~2^15-1 : -32768~32767) to unsigned short(0~2^16-1 : 0~65535)
     *
     * @param data
     * @return
     */
    public static int getUnsignedShort (short data){
        return data&0x0FFFF;
    }

    /**
     * java int (1 int == 4 byte == 32 bit)(-2^31~2^31-1 : -2147483648~2147483647) to unsigned short(0~2^32-1 : 0~4294967295)
     *
     * @param data
     * @return
     */
    public long getUnsignedInt (int data){
        return data&0x0FFFFFFFF;
    }

}

 

在项目要使用无符号整型,可以在项目中加入joou.jar ,用法如下

  1.  
    import static org.joou.Unsigned.*;
  2.  
     
  3.  
    // and then...
  4.  
    UByte b = ubyte(1);
  5.  
    UShort s = ushort(1);
  6.  
    UInteger i = uint(1);
  7.  
    ULong l = ulong(1);

 joou官网: http://www.jooq.org

google code主页:http://code.google.com/p/joou/

 

Java无符号整形

原文:https://www.cnblogs.com/QuickSlow/p/14049634.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!