| There is another, more subtle reason why you may choose to switch to unsigned integral types - this is for portability when reading & writing binary data.
The problem with negative numbers is that there is no agreed standard way to represent them. Some systems may use one's complement, where the range of numbers represented by 8 bits is -127 through to +127, other systems may use two's complement, where the range of numbers for 8 bits is -128 to +127 (Under one's complement, there is such thing as a 'negative zero' - when the sign bit is set to 1, and all other bits are zero)
This poses the problem that you must be sure what system your target platform uses, else your program can end up exhibiting very strange behaviour between different platforms.
On the other hand, unsigned integral types are all represented the same way, and differences depend on the size of a byte (in bits). (Although endian'ness and the number of bytes between different types are a factor)
Last edited by Bench : 07-23-2007 at 12:31 PM.
|