Do you have a question? Post it now! No Registration Necessary
- Subject
- Posted on
- two's compliment math
- 02-21-2006
posted on
February 21, 2006, 8:49 pm
February 21, 2006, 8:49 pm
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
subtraction?
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.
Anyone?
Thanks
JJ
Re: two's compliment math
but
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.
JJ
Site Timeline
- » Finding a comprehensive parametric contoller directory
- — Next thread in » Microcontroller Discussions
- » Dallas MTK problem
- — Previous thread in » Microcontroller Discussions
- » iPhone SUPER 80% discounts
- — Newest thread in » Microcontroller Discussions
- » Wyłącznik różnicowoprądowy
- — The site's Newest Thread. Posted in » Electronics (Polish)
- » A solid state replacement for the lowly 2D21 Thyratron tube...(sorry for the On-To...
- — The site's Last Updated Thread. Posted in » Electronics Repair