Forum Discussion
Altera_Forum
Honored Contributor
11 years agoTo subtract two unsigned numbers, I believe you do subtraction by indirect addition (a + (-b) = c where a is the minuend and b is the subtrahend). Meaning, convert the subtrahend using 2's complement and add to the minuend.
For example, to do 25 - 10, where 25 is 0001 1001 and 10 is 0000 1010 represented in binary, first convert 10 using 2's complement. 2's complement is a technique to negate a number in binary. The easiest way to take a 2's complement on a binary number is to go from left to right until you reach the first one in the number. So, for 10 it would be 10. Next, invert all bits after the first one. So, 10 would be 1111 0110. After you have negated the subtrahend, add to the minuend. So, 25: 0001 1001 + (-10): 1111 0110 = 0000 1111, or 15. Watch out for invalid answers. Hope this helps! 111 0001 1001 + -for each column, add the numbers at the place value, if you get 1+1 = 10 (2), this generates a carry 1111 0110 = 0000 1111 -video on adding/subtracting binary numbers http://us.yhs4.search.yahoo.com/yhs/search?hspart=ironsource&hsimp=yhs-fullyhosted_003&type=spd_wnzp01_14_26_ie¶m1=1¶m2=sid%3d4fc8850fbcd434850ee83ded58973a84%26ulng%3den-us%252cen%253bq%253d0.8%252cde%253bq%253d0.6%252cfr%253bq%253d0%26b%3dchrome%26ip%3d98.234.211.8%26p%3dspeedial%26x%3dac811232dd57e1a5%26dt%3ds908%26f%3d4%26a%3dspd_wnzp01_14_26_ie&p=adding+and+subtracting+binary+numbers