• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

int signed or unsigned ?

 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


F:\Binary Literal>javac Int.java
Int.java:5: error: integer number too large: 2147483648
System.out.println(2147483648);
^
1 error
 
Stephan van Hulst
Bartender
Pie
Posts: 6125
74
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you tell me how to represent -12 in binary? And what about -2147483648?
 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:Can you tell me how to represent -12 in binary? And what about -2147483648?



F:\Binary Literal>java Int
-12
 
Henry Wong
author
Marshal
Pie
Posts: 21420
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
saloni jhanwar wrote:

F:\Binary Literal>javac Int.java
Int.java:5: error: integer number too large: 2147483648
System.out.println(2147483648);
^
1 error



It has always been defined this way. The compiler will range check to make sure that decimal literals fit into the signed integer range.... but for octal and hexidecimal int literals (and now assuming for binary literals too), it just makes sure that it fits into 32 bits. The reason for this is because these types of literals, especially hexidecimal literals (before binary literals) were used to define bit patterns. And it is much easier to define them in an unsigned fashion.

Henry

 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic