short and char type in Java [duplicate]

char is unsigned, short is signed.

So while they are both 2-byte long, they use the sixteenth bit for different purposes.

The range of the char type is 0 to 2^16 – 1 (0 to 65535).

The short range is -2^15 to 2^15 – 1 (−32,768 to 32,767).

Leave a Comment