I have been pondering upon this question for quite a long time
In a c++ programmingbook i saw that it was written that
range of char is from -128 to 127{127-(-128)=256}.
Please can anybody tell me the meaning of this in details.
I knew that a char variable has a size of
1 byte which is equal to 8 bits.Since in 8 bits the max.
can be number can be 11111111 which is equal to 1x2^7+1x2^6.....
and so on .but 2^7 is equal to 128 and and 2^8 is 256.
I realised that this "Range" has something to do
with this .Plzzzzzzzz i would like someone to explain
this in details.Same with the case of an ip
address. Each number has to be between 0 and 256
But in char we used to write char='a'.
Does this "range" correspond to the ASCII value of a.
Plzz somebody somebodyn explain.
Thank You
Range Of Char Variable
Started by bodhi2016, Mar 11 2008 06:03 AM
2 replies to this topic
#1
Posted 11 March 2008 - 06:03 AM
|
|
|
#2
Posted 11 March 2008 - 08:10 AM
First, char does not necessarily have that range. It is platform/compiler dependent, and has that range as a minimum. Also, char is not necessarily signed.
8 bits gives you a range of 00000000 = 0 to 11111111 = 255. If the high bit is the sign bit, your range is 00000000 = 0 to 01111111 = 127 and 10000000 = -128 to 11111111 = -1
8 bits gives you a range of 00000000 = 0 to 11111111 = 255. If the high bit is the sign bit, your range is 00000000 = 0 to 01111111 = 127 and 10000000 = -128 to 11111111 = -1
#3
Posted 12 March 2008 - 01:59 PM
The range of char is from CHAR_MIN to CHAR_MAX. The number of bits in a byte (I'm using it interchangeably with char) is CHAR_BIT. These values are found in <limits.h>/<climits>.


Sign In
Create Account


Back to top









