View Single Post
  #6 (permalink)  
Old 07-23-2007, 12:26 PM
Bench Bench is offline
Full Programmer
Join Date: Jul 2007
Location: UK
Posts: 113
iTrader: (0)
Bench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished road
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)

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!

Last edited by Bench : 07-23-2007 at 12:31 PM.
Reply With Quote
The Following 2 Users Say Thank You to Bench For This Useful Post:
HelloWorld (07-23-2007), Lee (07-23-2007)