wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes is char unsigned 16 bit? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "is char unsigned 16 bit?" Watch "is char unsigned 16 bit?" New topic
Author

is char unsigned 16 bit?

saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
why datatype char is said to be unsigned ?
actually what is the difference between signed and unsigned?


A = HARDWORK B = LUCK/FATE If C=(A+B) then C=SUCCESSFUL IN LIFE else C=FAILURE IN LIFE
SCJP 1.4
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

A sign bit is used to indicate the sign of a number. Depending on whether the bit is 1 or 0 the number is considered positive or negative. A char need not be signed because it is used to represent unicode characters. Negative unicode characters just dont make sense. So a char is 16 bit unsigned.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Tom Adams
Ranch Hand

Joined: Feb 07, 2003
Posts: 56
The reason this is interesting is that by not supporting signed numbers a char can contain a larger number than say a short (also 16bit but supports signed numbers).

short can hold a number up to 2^15 - 1
char can hold a number uup to 2^16 - 1

Yes, chars are not meant to hold numbers...but you can assign a number to them.

See this post > http://www.coderanch.com/t/259063/java-programmer-SCJP/certification/char-representation-was-please-guide


Tom
saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
ok thanks but how many datatypes are there in java which has got both signed and unsigned ?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: is char unsigned 16 bit?
 
Similar Threads
how to shift unsigned binary byte(8bits)?
byte and char
Range related 2
Reading unicode characters from a file
chars