What exactly are signed and unsigned numbers? Please clarify.
Thanks..
Printable View
What exactly are signed and unsigned numbers? Please clarify.
Thanks..
In a strictly lingual sense, signed numbers may be negative or positive, while unsigned numbers are taken as positive. Usually, unsigned numbers can represent greater values, since in most implementations no space is left for a sign in an unsigned number.
Like the monkey explained, signed numbers can be positive or negative. Unsigned numbers are always positive.
In C++, unsigned variables can hold larger numbers, since all 8 bits (assuming the variable is 1 byte) can be used. While in signed variables, the last bit is used for the sign.
Strictly speaking, unsigned numbers are nonnegative, not necessarily positive.
How about the range? Why 0 to 255 for unsigned and -128 to 127 for signed in 1 byte? I don't quite get that. Can somebody please explain further?
Signed types need 1 bit for the sign, which means the maximum absolute value is approximately 1/2 that of an unsigned type. The C and C++ standards allow three types of signed integral arithmetic: two's complement, ones' complement, and sign-magnitude. Most modern machines use two's complement, in which there is one extra value at the negative end (for example -128 to +127). Ones' complement and sign-magnitude have a symmetric range (for example -127 to +127).
Edit: http://en.wikipedia.org/wiki/Signed_...epresentations