• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Signed and Unsigned int

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The largest positive value is 2^31-1.
Here's some fun:
http://qa.jtiger.org/GetQAndA.action?qids=15&showAnswers=false
reply
    Bookmark Topic Watch Topic
  • New Topic