This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes SIGNED AND UNSIGNED Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "SIGNED AND UNSIGNED" Watch "SIGNED AND UNSIGNED" New topic
Author

SIGNED AND UNSIGNED

SHALINI PATEL
Ranch Hand

Joined: Oct 31, 2000
Posts: 41
HI everybody..
I have a silly doubt.. All integral literals(byte, short, int and char) r signed.....
Can somebody explain in simple words the difference between signed and unsigned literals.
Thanks in advance..
shalini
anil bisht
Ranch Hand

Joined: Nov 04, 2000
Posts: 81
hi
i suppose char is not signed its unsigned..
signed means if the MSB is 1( in bit representation) then the number is negetive.. else positive..
suppose for bytes
if this is signed
11111111 -> -1
if unsigned ( but java dosent support unsigned byte)
11111111 -> 255
HTH
anil
Javed Khan
Greenhorn

Joined: Nov 25, 2000
Posts: 22
It's not fair to say that all interger types in java are signed. It is not true. JLS says that 'char' is unsigned and it is part of integral type. All numeric data types are SIGNED.
char is the only UNSIGNED integral type.
The following example may clear the confusion.
int i=-1; //compiles
byte i=-1;//compiles.
char i=1;//compiles
char i=-1;//Explicit cast needed to convert int to char,because char type is UNSIGNED
char i=(char)-1;//compiles fine.
Correct me if I'm wrong.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SIGNED AND UNSIGNED
 
Similar Threads
making signed int to unsigned int ?
IBM mock
is char unsigned 16 bit?
Signed and Unsigned int
calling method ----doubt