zoukankan      html  css  js  c++  java
  • java Integer.MAX_VALUE+1

    public final class Integer extends Number implements Comparable<Integer> {
        /**
         * A constant holding the minimum value an {@code int} can
         * have, -2<sup>31</sup>.
         */
        @Native public static final int   MIN_VALUE = 0x80000000;
    
        /**
         * A constant holding the maximum value an {@code int} can
         * have, 2<sup>31</sup>-1.
         */
        @Native public static final int   MAX_VALUE = 0x7fffffff;
    ....
    }

    源码可以看出  常量 MAX_VALUE 的值为0x7fffffff(十六进制)转换成二级制为 0 1111111111111111111111111111111(二进制)

     有符号整型的最高位是符号位 最高位 1表示负数 

            int maxValue =Integer.MAX_VALUE;
            int minValue =Integer.MIN_VALUE;
            System.out.println(maxValue);
         //  0 1111111111111111111111111111111+1 => 1 1111111111111111111111111111111(溢出)
        
    int overFlow =maxValue+1; assert overFlow == minValue: "addtion overflow"; System.out.println(overFlow);      // 同理 assert minValue -1 ==maxValue ; System.out.println(minValue-1);
  • 相关阅读:
    js检测对象中是否存在某个属性
    ES6 笔记
    DataSet 用法
    CommandBehavior.CloseConnection有何作用
    SqlDataReader
    Listview.Finditem()函数用法
    Instr()函数用法
    StringBuilder与StringBuffer的区别
    [DllImport("kernel32.dll")]使用
    extern用法
  • 原文地址:https://www.cnblogs.com/itachilee/p/13366724.html
Copyright © 2011-2022 走看看