aspose file tools*
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
Author

Signed and Unsigned int

T Ko
Greenhorn

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
Sheriff

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
sscce.org
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
The largest positive value is 2^31-1.
Here's some fun:
http://qa.jtiger.org/GetQAndA.action?qids=15&showAnswers=false


Tony Morris
Java Q&A (FAQ, Trivia)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Signed and Unsigned int
 
Similar Threads
Can anyone pls explain about the output of this prog.
Signed and Unsigned int
making signed int to unsigned int ?
( int a = 2147483648 ) vs (int a = 2147483647 ; a=a+1 )
16 bit char ???