Jump to content

char data type.....

Featured Replies

In Java,

 

char is an unsigned data type

 

 

Does any one know what does "unsigned" mean in that sense???

 

thx

 

Albert

It means that the number is always going to be positive. There's no bit to signify whether the number is positive or negative. A char is just a 1-byte data type (holds integers from 0-255), and the associated integers are matched up with the ASCII table.

  • Author

Oh, so, do you mean that the left most bit of a byte is always 0 in char???

 

Albert

A char is just a 1-byte data type (holds integers from 0-255), and the associated integers are matched up with the ASCII table.

I think that you made a typo. In Java, the char data type is a 2 byte unsigned integer. The purpose of the 2 byte type was that Java was designed early on to support unicode.

  • Author

Any one can refer to my previous message??

 

thx

 

Albert

Oh' date=' so, do you mean that the left most bit of a byte is always 0 in char???

[/quote']

This is not correct. In a signed byte, there is one sign bit and 7 data bits. The maximum number of distinctions is 128 (2^7), which can be postive or negative, depending on the sign (range: -128 - +127). In the high order byte of the char type, there is no sign bit. Therefore, all 8 bits pertain to the value, the maximum number of distinctions of which is 256 (2^8), with the range 0 - 255.

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.