This is my second article on binary arithmetic. In this post, I will provide solved examples of binary numbers subtraction. When dealing with negative numbers you should know about the complement of a number. Before starting this post I would like to recommend you to know about the complement system and sign-magnitude representation of numbers. Here is a detailed article on this topic. Representation of negative numbers.
Key Questions:
-
How to perform binary numbers subtraction?
-
How to perform fractional binary numbers subtraction?
Binary Subtraction Rules:
A-B
|
Result
|
Borrow
|
0-0
|
0
|
0
|
1-0
|
1
|
0
|
0-1
|
1
|
1
|
1-1
|
0
|
0
|
Binary Subtraction Examples:
I would like to provide the decimal equivalent of each number for easy understanding. I used to check my results using this online converter. Binary to decimal converter. Let’s get started.
Case#1: Minuend>Subtrahend
We use un-complemented numbers for Subtraction. For example 20-15=5
20 is Minuend
15 is Subtrahend
Example#01:11101110)2-11001100)2
A = 11101110)2
B = 11001100)2
Borrow
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
|
A
|
1
|
1
|
1
|
0
|
1
|
1
|
1
|
0
|
|
B
|
–
|
1
|
1
|
0
|
0
|
1
|
1
|
0
|
0
|
Result
|
0
|
0
|
1
|
0
|
0
|
0
|
1
|
0
|
Check your result:
A = 11101110)2 = 238)10
B = 11001100)2 = 204)10
Result = 100010)2 = 34)10
Example#02:11001111.10)2-10101010.11)2
A = 11001111.10)2
B = 10101010.11)2
Borrow
|
1
|
1
|
1
|
|||||||||
A
|
1
|
1
|
0
|
0
|
1
|
1
|
1
|
1
|
.
|
1
|
0
|
|
B
|
–
|
1
|
0
|
1
|
0
|
1
|
0
|
1
|
0
|
.
|
1
|
1
|
Result
|
0
|
0
|
1
|
0
|
0
|
1
|
0
|
0
|
.
|
1
|
1
|
Check your result:
A = 11001111.10)2 = 207.5)10
B = 10101010.11)2= 170.75)10
Result = 100100.11)2 = 36.75)10
Case#2: Minuend<Subtrahend
For example 15-20=-5
15 is Minuend
20 is Subtrahend
There are two ways of solving this type of problem. Using
-
Sign magnitude system
-
Complement system (2’s complement)
Example#01: 00011001)2– 00100000)2
1. Sign Magnitude System:
A= +25)10=00011001)2
+32)10=00100000)2
B= -32)10 =10100000)2 according to sign-magnitude representation MSB shows the sign.
When working with a sign magnitude system avoid the sign bit during the calculation. So we have 7 bits.
Step 1: Omits the sign bit
A=0011001)2
B=0100000)2
Step 2: perform subtraction like this 32)10-25)10 OR 0100000)2 – 0011001)2
Borrow
|
1
|
1
|
1
|
1
|
1
|
|||
B
|
0
|
1
|
0
|
0
|
0
|
0
|
0
|
|
A
|
–
|
0
|
0
|
1
|
1
|
0
|
0
|
1
|
Result
|
0
|
0
|
0
|
0
|
1
|
1
|
1
|
Step 3: include the sign bit.
Result=10000111)2=-7)10
Check your result:
A= +25)10=00011001)2
B= -32)10 =10100000)2
Result=-7)10=10000111)2
2. Complement System:
A= +25)10=00011001)2
+32)10=00100000)2
Evaluate 2’s complement of 00100000)2
2’s Complement=11100000)2
In this technique, we will perform addition like this
+25+[-32] or +25+[complement of 32]
A
|
0
|
0
|
0
|
1
|
1
|
0
|
0
|
1
|
|
B
|
1
|
1
|
1
|
0
|
0
|
0
|
0
|
0
|
|
Result
|
+
|
1
|
1
|
1
|
1
|
1
|
0
|
0
|
1
|
Carry
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
Result: 11111001)2
The result is -7)10. We get the complemented answer. If you want to check your answer you can easily evaluate the decimal value of the complemented number.
Check your answer:
You can check your result using an online converter. You are using signed numbers so please make sure that you choose the option ‘signed’. You can do it manually by converting binary to decimal. You know the decimal to binary conversion.
11111001)2=(-1*27)+(1*26)+(1*25)+(1*24)+(1*23)+(0*22)+(0*21)+(1*20)
=-128+64+32+16+8+0+0+1
=-128+121
=-7)10
Example#02: 00100000)2-00101110)2
A=32)10=00100000)2
+46=00101110)2
B=-46=10101110)2 according to sign-magnitude representation MSB shows the sign.
When working with a sign magnitude system avoid sign bit during the calculation.
Step 1: Omits the sign bit
A=0100000)2
B=0101110)2
Step 2: perform subtraction like this 46)10-32)10 OR 0101110)2 – 0100000)2
Borrow
|
||||||||
B
|
0
|
1
|
0
|
1
|
1
|
1
|
0
|
|
A
|
–
|
0
|
1
|
0
|
0
|
0
|
0
|
0
|
Result
|
0
|
0
|
0
|
1
|
1
|
1
|
0
|
Result= 10001110)2= -14)10 including sign bit.
Check your result:
A= +32)10=00100000)2
B= -46)10 =10101110)2
Result=-14)10=10000111)2
2. Complement System:
A=+32)10=00100000)2
+46)10=00101110)2
Evaluate 2’s complement of this 00101110
2’s complement = 11010010)2
In this technique, we will add complement.
+32+[-46] Or +32+[complement of 46]
Perform addition 00100000)2+ 11010010)2
A
|
0
|
0
|
1
|
0
|
0
|
0
|
0
|
0
|
|
B
|
1
|
1
|
0
|
1
|
0
|
0
|
1
|
0
|
|
Result
|
+
|
1
|
1
|
1
|
1
|
0
|
0
|
1
|
0
|
Carry
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
Result=1110010)2 = -14)10
Check your result:
You can check your result using an online converter. You are using signed numbers so please make sure that you choose the option ‘signed’. You can do it manually by converting binary to decimal. You know the decimal to binary conversion.
11110001)2 = (-1*27)+(1*26)+(1*25)+(1*24)+(0*23)+(0*22)+(1*21)+(0*20)
=-128+64+32+16+0+0+2+0
=-128+114
=-14)10