This week's book giveaway is in the Design forum.We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!

# Signed and Unsigned int

T Ko
Greenhorn
Posts: 1
The value 2147483647 is the max. value of a value i which is defined as int. Also the value of -1 when assigned to a unsigned int , it will 2147483647. How can we find the 2147483647 is actually represents -1 when we consider unsigned integers. Is there any function which converts unsigned int to signed int and vice versa.

marc weber
Sheriff
Posts: 11343
In Java, all numeric primitives are signed. There is no such thing as an unsigned int.

A Java int is 32 bits. So the binary representation of -1 as an int is 32 ones, which translates to 4294967295 in base 10 (that is, (2^32)-1).

But 2147483647 is only (2^31)-1. This is the largest positive value of a Java int.
[ April 25, 2005: Message edited by: marc weber ]

Tony Morris
Ranch Hand
Posts: 1608
The largest positive value is 2^31-1.
Here's some fun: