Question:
how is binary subtraction done on the following?
lazy_boy
2012-12-27 04:10:11 UTC
ok i have the following equation i need to solve:

110101
-
011110

I know from using a binary calculator the answer should be 010111

BUT I can not seem to do it by hand?

I know the rules of binary subtraction are:

 0 ‐ 0 = 0  
 0 ‐ 1 = 1, and borrow 1 from the next more significant bit  
 1 ‐ 0 = 1  
 1 ‐ 1 = 0  

Could anybody show me the steps needed?

Thanks
Five answers:
O(n)
2012-12-27 05:19:33 UTC
The problem with your binary subtraction table is that it says nothing for when, in the 2nd case, the next more significant digit is ALREADY a 0 and therefore if you borrow one it becomes "-1" which is meaningless in this context.

What the rules table meant to say is: borrow the first available 1 from the next more significant digits, but even this way it's not a good description.



For this reason, it's better to think of subtraction as addition with the opposite number.



I.e. instead of a - b think of a + (-b)



This is true regardless of the base being 10 or 2 or whatever else.



Now, in binary form, the opposite of a number is its 2's complement, which you get by:

1. inverting all digits

2. adding 1



E.g. the opposite of 1, when we have 8 digits to write down the numbers, would be:

0. 1 = 00000001 (write down 1 in 8-digit binary form)

1. 11111110 (invert the digits)

2. 11111110 + 00000001 = 11111111 . This is -1 in 2's complement form.



So in your problem, the available number of digits is obviously 6.



110101 - 011110 = 110101 + ( -011110 )



-011110 = 100001 + 000001 = 100010



So 110101 + ( -011110 ) = 110101 + 100010 = 010111



(there's a carry produced in the last bit which we disregard as we are limited to 6 digits)





With your rules table it's more complicated:



110101

-

011110



1st digit: 1 - 0 = 1



2nd digit: 0 - 1 = 1

and we must borrow a 1 from the 3rd digit of the top number. The 3rd digit of the top number is 1, so now it becomes 0.



3rd digit: instead of 1 - 1, we now have to do 0 - 1 because of the carry in step 2.

So we do: 0 - 1 = 1



and we need to borrow another 1 from the 4th digit of the top number. The 4th digit of the 4th number is already 0 though, so we must borrow 1 from 5th and 4th digits combined:

5th and 4th is 10, so after borrowing 1, 5th and 4th become 01



4th digit: Recall that due to step 3, 4th digit of the top number is now 1

So we do 1 - 1 = 0



5th digit: Recall that due to step 3, 5th digit of the top number is now 0

So we do 0 - 1 = 1 and we borrow 1 from the 6th digit of the top number, which now becomes 0



6th digit: Recall that due to step 5, the 6th digit of the top number is now 0

So we do 0 - 0 = 0



Writing the results from bottom to top, we get:



0 1 0 1 1 1
david h
2012-12-27 05:52:35 UTC
110101

-

011110

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

------- 1

As you said 1 - 0 = 1 so starting at the right hand column 2^0 the first digit answer is 1



110101 can be written as

110021

-

011110

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

-------11

Is hard to type this answer but for the second digit column 2^1 we are trying to subtract 1 from zero so we need to borrow 2 from the next colmun the 2^2 column so the second column can be rewriten using a 2



110021 we can not take 1 from 0 for the 3rd column so need to rewrite the top line as

101221 we can now subtract 1 from 2

-

011110

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

----111





101221

-

011110

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

0111 This is straight forward 1 - 1 = 0 for the 2^3 column





101221 Again we can not take 1 from 0 so need to rewrite the top line as

021221

-

011110

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

10111



There is no need to convert to any other base and do the calulation in base 10 , how ever you must remember when you can not take 1 from 0 , you must rewrite the top line with a 2 and reduce the the next higher power columns by 1 to keep the sum correct.

This can be seen as looking at

110101 as meaning 1*2^5 + 1*2^4 + 0*2^3 +1*2^2 + 0*2^1 +1*2^0 subtracting

011110 as ------------- 0*2^5 + 1*2^4 + 1*2^3 +1*2^2 + 1*2^1 +0*2^0

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

adding a heading 32 + 16 + 8 + 4 + 2 + 1

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

in base 10 = 32 + 16 + 0 + 4 + 0 + 1

minus 0 + 16 + 8 + 4 + 2 + 0

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

= 32 +0 -8 + 0 - 2 + 1

= 32-11 = 21

10101 = 16 + 0 + 4 + 0 + 1 = 10101 binary
fcas80
2012-12-27 04:55:46 UTC
110101 = 1*2^5 + 1*2^4 + 0*2^3 +1*2^2 + 0*2^1 + 1*2^0 = 53 in base 10

011110 = 0*2^5 + 1*2^4 + 1*2^3 +1*2^2 + 1*2^1 + 0*2^0 = 30 in base 10



53-30 = 23 in base 10 = 1*2^4 + 0*2^3 + 1*2^2 + 1*2^1 + 1*2^0 = 10111
anonymous
2016-12-10 08:01:23 UTC
i think of in a signed documents style (a minimum of they way their signed in recent times) the bit development is inverted for detrimental numbers so 0000 0101 could be 10 and 1111 1010 could be -10 or maybe it rather is any opposite direction around besides for that reason you maximum in all probability could desire to do the maths in binary to determine it out 0110 1110 0001 1010 -------------- 0111 2120 you are able to now no longer have 2's there so which you may desire to attempt to function one to the bit to the left and reset the two to 0 0111 2120 0112 0200 0120 1000 0200 1000 1000 1000 hmm based at one among those gadget you're utilising the signing technique *could* be to purely set the left-maximum bit to a million which could be a flag that asserts that the linked fee of all of the different bits could desire to be perceived as a detrimental so if that's the case then definite signed overflow did ensue yet earlier you place that down simply by fact the respond seek for on your e book or despite different materials you have on how the signing is being accomplished simply by fact there are 2 innovations and that i'm uncertain in the event that they're coaching you the previous way or the hot way.
daSVgrouch
2012-12-27 05:07:54 UTC
you seem to have all the steps needed, you just need to apply them


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