Do you have a question? Post it now! No Registration Necessary
- Posted on
- two's compliment math
February 21, 2006, 8:49 pm
rate this thread
Have been trying to do 32bit signed subtraction using two's compliment but I
can't seem to get correct figures if either (or both)of the original
operands are negative.
For a simple example in real math, 3 subtract -2 is 5, but the two's
compliment routines say the result is -1.
Am I missing something or is two's compliment unsuitable for mixed sign
The routines are public domain and work precisely for two positive operands
so it appears the routines are working correctly.
Do I need to go to another form of subtraction(fixed/floating point)?
What I really want is to find a quick way to find the difference between two
32bit signed numbers.
Re: two's compliment math
Yes, you negate one operand and add i.e. invert all bits, add 1 and then add
that to the other operand which works just fine but my question was can
two's compliment deal with all signs at both ends of the equation...the code
I have say's apparently not.
- » Finding a comprehensive parametric contoller directory
- — Next thread in » Microcontroller Discussions