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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM