|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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 |
| Sponsored Links |
|
|
|
|||||
|
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
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Programming is a branch of mathematics. |
|
|||
|
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>.
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| char * and char[] problem | Anirban Chakraborty | C and C++ | 5 | 11-30-2007 09:32 AM |
| a little problem with char array | worried_student | C and C++ | 2 | 11-23-2007 11:18 AM |
| Works when i have an int | NoName | C and C++ | 1 | 08-28-2007 12:25 AM |
| Java:Tutorial - The Variable | John | Java Tutorials | 0 | 12-09-2006 10:59 AM |
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |