# integer range

Madan, Gopal

Ranch Hand

Posts: 86

Madan, Gopal

Ranch Hand

Posts: 86

Nain Hwu

Ranch Hand

Posts: 139

posted 14 years ago

From JLS �15.17.1:

1000000*1000000 results in an overflow. The lower-order

32 bits (int is 32 bits) are 0xd4a51000 which is -727,379,968.

[This message has been edited by Nain Hwu (edited October 09, 2001).]

My question is how I got -727,379,968

From JLS �15.17.1:

If an integer multiplication overflows, then the result is the low-order bits of the mathematical product as

represented in some sufficiently large two's-complement format. As a result, if overflow occurs, then the

sign of the result may not be the same as the sign of the mathematical product of the two operand values.

1000000*1000000 results in an overflow. The lower-order

32 bits (int is 32 bits) are 0xd4a51000 which is -727,379,968.

[This message has been edited by Nain Hwu (edited October 09, 2001).]

Madan, Gopal

Ranch Hand

Posts: 86

Nain Hwu

Ranch Hand

Posts: 139

posted 14 years ago

Madan,

I used the toHexString() method in class Integer.

Here is what I did:

Here is the output:

Notice that 0xd4a51000 is a negative integer value (in java,

integer is stored as two complement value).

Looks like NT calc treats it as a positive value, which gives

you 3567587328.

Hope this help.

I used the toHexString() method in class Integer.

Here is what I did:

Here is the output:

D:\pfe101i>java Test

d4a51000

-727379968

Notice that 0xd4a51000 is a negative integer value (in java,

integer is stored as two complement value).

Looks like NT calc treats it as a positive value, which gives

you 3567587328.

Hope this help.

Don't get me started about those stupid light bulbs. |