Question:
Having Trouble with Binary Subtraction?
Toby
2013-02-15 07:27:37 UTC
Ok, so I'm currently studying A level computing, and I am completely puzzled as to how binary subtraction works. I can do addition, but subtraction is just confusing me.

So the example question I have is 45 - 34

45 as binary is: 00101101
34 as binary is: 11011110

When I do the subtraction, I go from right to left, and carry any numbers that don't work. For example, 0-1 won't work, so I carry another 1 over so it becomes 2, because 10 = 2. It's extremely hard to explain what I've done on here without a drawn demonstration, but after getting to the last two columns the subtraction doesn't seem to work. If this makes any sense, when I get to the last two
0-1's I can't do it, because nothing can be borrowed to make the zero greater than the one. I'm so sorry if this is confusing, but it's just so frustrating as no tutorials online have helped much.

Thanks
Five answers:
AnalProgrammer
2013-02-15 07:36:00 UTC
This is correct.

45 as binary is: 00101101



This

34 as binary is: 11011110

is also correct except that it is -34 shown in 2's complement form.



So now your subtraction problem is solved.

Just add the numbers together. Any bits carried over beyond the length of -34 ignore.



Have fun.
husoski
2013-02-15 08:13:16 UTC
First, your binary value for 34 appears to be the two's complement form of -34. That makes it look like you are doing subtraction by "complement and add". If so, just add those two numbers in binary.



0 0 1 0 1 1 0 1

1 1 0 1 1 1 1 0

---------------------

0 0 0 0 1 0 1 1



The leading bit is 0, so the result is positive. 16 + 2 + 1 = 19 is the difference.



To follow that, from right to left, add (top bit) + (bottom bit) + carry in each position. The carry value into the rightmost bit is 0.



1 + 0 + 0 = 1 (carry 0)

0 + 1 + 0 = 1 (carry 0)

1 + 1 + 0 = 0 (carry 1)

1 + 1 + 1 = 1 (carry 1)

0 + 1 + 1 = 0 (carry 1)

1 + 0 + 1 = 0 (carry 1)

0 + 1 + 1 = 0 (carry 1)

0 + 1 + 1 = 0 (carry 1)



Then read the sum bits from bottom to top to get 00001011.



If you want to subtract (as in "0-1 won't work") then don't complement first.



0 0 1 0 1 1 0 1

0 0 1 0 0 0 1 0

---------------------

0 0 0 0 1 0 1 1



The only borrow needed is in the 2nd column from the right.
anonymous
2013-02-15 07:36:38 UTC
Binary runs from right to left as follows:



11111111 = 128 + 64 + 32 + 16+ 8 + 4 + 2 + 1



Therefore:



00101101 = 0 + 0 + 32 + 0 + 8 + 4 + 0 + 1 or 45 in decimal



11011110 = 128 +64 + 0 + 16 + 8 + 4 + 2 + 0 or 222 in decimal (def not 34)



34 in binary would be 00100010



45 - 34 = 00001011 in binary
anonymous
2013-02-15 07:34:45 UTC
If a number is represented as a 2s complement then you ADD or in order to perform the subtraction!



Just remember to drop any overflow bits. There is more to it than this, of course.
?
2016-12-05 23:43:29 UTC
There would not seem a trend. i propose you to examine greater approximately Pascal's Triangle and Stirling numbers and notice if some thing comes up. i think of you will discover so lots greater cooler issues in common selection theory.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...