File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Signed and Unsigned int Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Signed and Unsigned int" Watch "Signed and Unsigned int" New topic

Signed and Unsigned int

T Ko

Joined: Apr 25, 2005
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

Joined: Aug 31, 2004
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 ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
The largest positive value is 2^31-1.
Here's some fun:

Tony Morris
Java Q&A (FAQ, Trivia)
I agree. Here's the link:
subject: Signed and Unsigned int
It's not a secret anymore!