zoukankan      html  css  js  c++  java
  • java 整型

    byte(1字节)、short(2字节)、int(4字节)、long(16字节)

    java中前缀加上0b或者0B就可以写二进制数,前缀加上0就可以写八进制数,前缀加上0x或者0X就可以写十六进制数

    一个字节是8位,最高位是符号位,最高位为0则是正数。最高位为1则是负数,

    先了解原码、反码和补码的表示规则:

    0的表示:

                   原码:有正零和负零之分,[+0]补=0000 0000,[-0]补=1000 0000;

                   反码:同样有两种表示方法,[+0]反=0000 0000 ,[-0]反=1111 1111;

                   补码:零只有一种表示方法,不分正负,[0]补=0000 0000;

    所以可以得出取值范围(因为0和其他一些问题,采用补码,了解详情https://blog.csdn.net/ai_yue/article/details/82777806):

    byte:最大0111 1111 为 127 最小 1000 0000 为 -128

    short:0111 1111 1111 1111 为 32767  1000 0000 0000 0000 为 -32768

    int:0111 1111 1111 1111 1111 1111 1111 1111 为  2147483647

           1000 0000 0000 0000 0000 0000 0000 0000 为 -2147483648

    long: 9223372036854775807~-9223372036854775808

    int和Integer问题:

    Integer.valueOf(int i)方法,在传入i的值不在-128和127之间时,便new出一个新的Integer对象;如果范围在-128和127之间,则直接从IntegerCache缓存中取出i  对应的Integer对象。所以

            Integer i = Integer.valueOf(127);
    	Integer j = 127;
    	System.out.println(i == j);  //true
    	
    	
    	Integer x = Integer.valueOf(128);
    	Integer y = 128;
    	System.out.println(x == y);  //false
    

      

  • 相关阅读:
    (转载)C#如何在任务管理器中不显示指定的窗体
    Windows上配置Mask R-CNN及运行示例demo.ipynb
    如何选择普通索引和唯一索引?
    relay(跳板机)搭建
    javascript 9x9乘法口诀表
    canvas画布爆炸
    Chrome Network Timing 解释
    JavaScript中对数组的定义
    jquery each 和 map 区别
    css 兼容性转换网站
  • 原文地址:https://www.cnblogs.com/guuyoog/p/11125650.html
Copyright © 2011-2022 走看看