| | |
Range of int
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2006
Posts: 67
Reputation:
Solved Threads: 1
Unsigned char is 1 byte long..
it's range is from -128 to 127
Most significant bit is sign bit to indicate whether the char has positive or negative value and the rest 7 bits are meant for storing the actual value of char... so the max +ve value of char can be 127 as expected but in the -ve side how can it be -128 ???
it's range is from -128 to 127
Most significant bit is sign bit to indicate whether the char has positive or negative value and the rest 7 bits are meant for storing the actual value of char... so the max +ve value of char can be 127 as expected but in the -ve side how can it be -128 ???
0xFF is the largest value that can be stored in one byte, for signed integers that is 0xFF/2, which is 127.5 (use a calculator if you must). Since you can put 0.5 in a byte, one side is 127 and the other is 128 so that 127+128 = 255 (0xFF).
limits.h contains the upper and lower limits of all numeric data types supported by your compiler.
limits.h contains the upper and lower limits of all numeric data types supported by your compiler.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Read up on how Two's Complement works and hopefully you'll see. It comes down to 0 being counted as a positive number, and 1-127+0 is a total of 128 numbers; there's an equal number of negatives, but since it doesn't include 0, you get 1-128.
At least; it can be larger.
Two's complement?
•
•
•
•
Most significant bit is sign bit to indicate whether the char has positive or negative value and the rest 7 bits are meant for storing the actual value of char... so the max +ve value of char can be 127 as expected but in the -ve side how can it be -128 ???
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Just noticed... an unsigned char has values 0 to 255, and a signed char is -128 to 127.
That said, I seem to recall in some discussions that a char is strictly defined as a single byte (8 bits) by the standard but I'm not sure where to double check that...
That said, I seem to recall in some discussions that a char is strictly defined as a single byte (8 bits) by the standard but I'm not sure where to double check that...
•
•
•
•
Just noticed... an unsigned char has values 0 to 255, and a signed char is -128 to 127.
That said, I seem to recall in some discussions that a char is strictly defined as a single byte (8 bits) by the standard but I'm not sure where to double check that...
Last edited by Dave Sinkula; Feb 17th, 2007 at 4:30 am.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
>Byte is not defined as 8 bits then what is it defined as?
It's defined as whatever the implementation wants. The standard only specifies that sizeof ( char ) be 1, and at least 8 bits. That happens to be the most common definition of a byte, but systems other than your PC also support C and don't have the same definition.
It's defined as whatever the implementation wants. The standard only specifies that sizeof ( char ) be 1, and at least 8 bits. That happens to be the most common definition of a byte, but systems other than your PC also support C and don't have the same definition.
I'm here to prove you wrong.
![]() |
Similar Threads
- (Noob) need some help w/ Prime Numbers (C++)
- Targeting a number within a set of integers (C)
- Whats wrong with this class??? (C++)
- random number generator (C++)
- Base converter (C++)
- I don't know how to start to determine what hand of the poker, any ideas??? (Java)
Other Threads in the C++ Forum
- Previous Thread: Failing an input
- Next Thread: Time check problem
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






