Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Two words - <strong>integer overflow</strong></p> <p>While not an expert in python, I assume it may expand the size of the integer type according to its needs.</p> <p>In Java, however, the size of an <code>int</code> type is fixed - 32bit, and since <code>int</code> is signed, we actually have only 31 bits to represent positive numbers. Once the number you assign is bigger than the maximum, it overflows the int (which is - there is no place to represent the whole number). </p> <p>While in the C language the behavior in such case is undefined, in Java it is well defined, and it just takes the least 4 bytes of the result.</p> <p>For example:</p> <pre><code>System.out.println(Integer.MAX_VALUE + 1); // Integer.MAX_VALUE = 0x7fffffff </code></pre> <p>results in:</p> <pre><code>-2147483648 // 0x7fffffff + 1 = 0x800000000 </code></pre> <p><strong>Edit</strong></p> <p>Just to make it clearer, here is another example. The following code:</p> <pre><code>int a = 0x12345678; int b = 0x12345678; System.out.println("a*b as int multiplication (overflown) [DECIMAL]: " + (a*b)); System.out.println("a*b as int multiplication (overflown) [HEX]: 0x" + Integer.toHexString(a*b)); System.out.println("a*b as long multiplication (overflown) [DECIMAL]: " + ((long)a*b)); System.out.println("a*b as long multiplication (overflown) [HEX]: 0x" + Long.toHexString((long)a*b)); </code></pre> <p>outputs:</p> <pre><code>a*b as int multiplication (overflown) [DECIMAL]: 502585408 a*b as int multiplication (overflown) [HEX]: 0x1df4d840 a*b as long multiplication (overflown) [DECIMAL]: 93281312872650816 a*b as long multiplication (overflown) [HEX]: 0x14b66dc1df4d840 </code></pre> <p>And you can see that the second output is the least 4 bytes of the 4 output</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload