View Single Post
  #10 (permalink)  
Old 07-23-2007, 03:58 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
Indeed. The Ones complement vs twos complement problem only occurs when reading binary data between different kinds of hardware (Luckily most modern PC hardware uses twos complement anyway). The kind of situations where you'll encounter the difference will be embedded devices, old mainframes, Digital signal processors, calculators..

Provided you don't attempt to mix signed and unsigned values in the same expression, you won't go too far wrong.

(Here's a horrible example of what may go wrong if you do )
Code:
#include <iostream>

int main()
{
    char ch = -1;
    unsigned int i = ch;
    std::cout << i ;
}

__________________

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 04:06 PM.
Reply With Quote
The Following User Says Thank You to Bench For This Useful Post:
Lee (07-23-2007)