Jump to content

Recommended Posts

Posted

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.

Posted
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.

Posted

I missed the "in Java" bit, sorry. In most of the programming languages I know, a char is only 1 byte, but fair enough :)

Posted
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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

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.