The Student Room Group

Binary subtraction with number that require more than 1 byte.

Right, in our lecture we learned about 2's compliment and binary subtraction using addition. But we have only been taught how to do it with 8 bits.

So if a question says 425 - 312, I'm kinda baffled on how it can be done as both numbers require more than 8-bits.

On lower numbers (75 - 30), I would convert both to binary, invert the 30 and add a 1 to it then add the both binary numbers together and convert back to decimal.

Anyone know how it can be done, or how the computer does subtraction with larger numbers?
Just extend the number of bits

425 = 0001 1010 1001
312 = 0001 0011 1000
-312 = 1110 1100 1000

0001 1010 1001
1110 1100 1000 +
---------------------
0000 0111 0001 = 113

N.B. a quick way to convert a number to it's negative form is: starting from the right hand side, copy each digit up to and including the first '1', and invert all the rest.
I invert the number, plus 1, and that's the negative. The signed number can then be seen as positive or negative using the last most significant bit.

I'll have to play about with extending them though to do large numbers.

Latest

Trending

Trending