Binary Arithmetic Operations
Presented by
Dr. Shirshendu Roy
Homepage - https://digitalsystemdesign.in/
Course - Digital Electronics
Dr. Shirshendu Roy Binary Arithmetic Operations 1 / 13
Binary Addition
Value of a binary digit is either ’0’ or ’1’. Thus addition of two binary digits
can be greater than one bit. Addition of two binary bits is shown below.
0
0
0
0
+
0
1
1
0
+
1
0
1
0
+
1
1
0
1
+
Sum
Carry Sum
Carry
Sum
Carry
Sum
Carry
In binary addition, when both the digits are ’1’ then addition result is greater
than 1 bit. The extra bit is called as Carry. In this situation, Carry is
generated.
Dr. Shirshendu Roy Binary Arithmetic Operations 2 / 13
Addition of Three Bits
0
0
0
0
+
0
1
1
0
+
0
0
1
0
+
0
1
0
1
+
Sum
Carry Sum
Carry
Sum
Carry
Sum
Carry
0 0
1 1
1
0
1
0
+
1
1
0
1
+
1
0
0
1
+
1
1
1
1
+
Sum
Carry Sum
Carry
Sum
Carry
Sum
Carry
0 0
1 1
A
B
C
Dr. Shirshendu Roy Binary Arithmetic Operations 3 / 13
Binary Subtraction
Thus subtraction of two binary digits can not be greater than one bit. Sub-
traction of two binary bits is shown below.
0
0
0
0
1
1
-
1
0
1
1
1
0
Difference
1
Borrow
Difference
Difference Difference
-
0
Borrow
-
0
Borrow -
0
Borrow
In binary subtraction, bit ’1’ can not be subtracted from bit ’0’. Thus to do
this subtraction extra bit ’1’ is borrowed. The extra bit is called as Borrow.
Dr. Shirshendu Roy Binary Arithmetic Operations 4 / 13
Subtraction Operation for Three Bits (A − B − C)
0
0
0
-
0
1
1
-
0
0
1
-
0
1
0
-
0 0
1 1
1
0
1
-
1
1
0
-
1
0
0
-
1
1
1
-
0 0
1 1
1
Borrow
A
B
C
Difference Difference Difference
Difference
Difference
Difference
Difference
Difference
0
Borrow
1
Borrow
1
Borrow
1
Borrow
0
Borrow
0
Borrow
0
Borrow
Dr. Shirshendu Roy Binary Arithmetic Operations 5 / 13
Strategy for Subtraction Operation fo 3-bits
The subtraction operation for 3-bits is
A − B − C = A − (B + C)
First, B + C is evaluated and the result is subtracted from A. An example
is shown below
1
1
-
0
A
B
C
?
1
0
A
(B+C)
?
0
-
Subtraction
Not Possible
(A < (B + C))
1
0
A
(B+C) 0
-
1
Borrow
0
Difference
Dr. Shirshendu Roy Binary Arithmetic Operations 6 / 13
Addition/Subtraction using One’s Complement
There is no subtraction operation in One’s Complement Number System.
Only addition operation is carried out.
In the operation (X − Y ), X is added to −Y (represented in One’s Com-
plement Number System).
In this case, the result can be written like
X + (2n
− ulp) − Y = (2n
− ulp) + (X − Y ) (1)
where ulp = 20
= 1. This can be explained below with the value of n = 8
X + (256 − 1) − Y = 255 + (X − Y ) (2)
Example: X = 5, Y = 6 then find X − Y for n = 8.
In this case, the result is 28
− 1 + X − Y = 256 + 5 − 6 = 254.
Here, 254 is one’s complement representation of −1.
Dr. Shirshendu Roy Binary Arithmetic Operations 7 / 13
Addition/Subtraction Example in One’s Complement
0 0 1 1 0 1 1 0
1 1 0 1 0 1 1 1
+
0
1
0
1
1
0
0
0
0
1
1
1
0
1
1
1
(54)10
(−40)10
(13)10
A
B
Carry
Cout
0
1 1 0 0 1 0 0 1
0 0 1 0 1 0 0 0
+
0
1
0
0
0
1
1
1
1
0
0
0
1
0
0
0
(−54)10
(40)10
(−14)10
A
B
Carry
Sum
0
Cin Cin
Cout
0 0 1 1 0 1 1 0
+
0
0
1
1
1
0
0
1
0
0
0
0
0
0
1
0
(54)10
(94)10
A
B
Carry
Sum
Cout
0
1 1 0 0 1 0 0 1
+
1
0
0
0
0
0
1
0
1
1
1
1
1
1
0
1
(−54)10
(−14)90
A
B
Carry 0
Cin Cin
0 0 1 0 1 0 0 0 (40)10 1 1 0 1 0 1 1 1 (−40)10
1
+
0
1
1
1
0
0
0
0 (14)10
Sum
Cout
1
+
1
0
0
0
0
1
0
1 (−94)10
Sum
Initially Cin = 0. A correction step is required whenever Cout bit is ’1’. In
the correction step, this bit is added to the result at LSB position.
Dr. Shirshendu Roy Binary Arithmetic Operations 8 / 13
Addition/Subtraction using Two’s Complement
There is also no subtraction operation in Two’s Complement Number System.
Only addition operation is carried out.
In the operation (X − Y ), X is added to −Y (represented in Two’s Com-
plement Number System).
In this case, the result can be written like
X + 2n
− Y = 2n
+ (X − Y ) (3)
Example: X = 5, Y = 6 then find X − Y for n = 8.
In this case, the result is 28
+ X − Y = 256 + 5 − 6 = 255.
Here, 255 is two’s complement representation of −1.
Dr. Shirshendu Roy Binary Arithmetic Operations 9 / 13
Addition/Subtraction Example in Two’s Complement
0 0 1 1 0 1 1 0
1 1 0 1 1 0 0 0
+
0
0
1
1
1
0
0
0
0
1
0
0
1
1
1
1
(54)10
(−40)10
(14)10
A
B
Carry
Sum
Cout
0
1 1 0 0 1 0 1 0
0 0 1 0 1 0 0 0
+
0
0
1
0
0
1
1
1
1
0
0
0
1
0
0
0
(−54)10
(40)10
(−14)10
A
B
Carry
Sum
0
Cin Cin
Cout
0 0 1 1 0 1 1 0
+
0
0
1
1
1
0
0
1
0
0
0
0
0
0
1
0
(54)10
(94)10
A
B
Carry
Sum
Cout
0
1 1 0 0 1 0 1 0
+
0
0
1
0
0
0
1
0
1
1
0
0
1
1
0
1
(−54)10
(−14)90
A
B
Carry
Sum
0
Cin Cin
Cout
0 0 1 0 1 0 0 0 (40)10 1 1 0 1 1 0 0 0 (−40)10
Initially Cin = 0. Here, no correction step is required. Cout bit indicates only
overflow condition.
Dr. Shirshendu Roy Binary Arithmetic Operations 10 / 13
Binary Multiplication
Multiplication between two binary numbers A = A2A1A0 and B = B2B1B0
can be written as
S = A0 × (B2 × 22
+ B1 × 21
+ B0 × 20
) + A1 × (B2 × 22
+ B1 × 21
+
B0 × 20
) + A2 × (B2 × 22
+ B1 × 21
+ B0 × 20
) (4)
1 0 0 1 0 1
1 0 0 1
×
1 0 0 1 0 1
×
0
0
0
0
0
0
×
0
0
0
0
0
0
1 0 0 1 0 1 ×
×
×
×
0 0 1 1 0 1
1
0
1
0
(333)10
(37)10
(09)10
1 0 0 1 0 1
1 0 0 1
×
1 0 0 1 0 1
×
0
0
0
0
0
0
×
0
0
0
0
0
0
1 0 0 1 0 1 ×
×
×
×
0 0 1 1 0 1
1
0
1
0
(2.6015)10
(2.3125)10
(1.125)10
In binary multiplication, if A has n bits and B has m bits then the multipli-
cation result will have n + m + 1 bits.
If n bits and m bits are used to represent fractional part in A and B respec-
tively then m+n bits will be reserved for fractional part in the multiplication
result.
Dr. Shirshendu Roy Binary Arithmetic Operations 11 / 13
Binary Division
The basic equation of a division operation is
N = Q.D + R = Q3.23
.D + Q2.22
.D + Q1.21
.D + Q0.20
.D + R (5)
Here, N is the numerator, D is the denominator, Q is the quotient and R is
the residual. The division operation shown above is for 4-bit Quotient width.
1 1 0 0 1
1 0 1
1 0 1
1 0 1
−
1
0
0 0 1
1 0 1
−
0
0 0
0 0
1 1 1 0 1 0 0 0 0 0
1 1 0 0
1 0 1 0 0
1 1 0 0
1 0 0 0 0
1 1 0 0
1 1 0 0
0 1 0 0
1 0 0 1 1 0 1
Q
D
R
N
Dr. Shirshendu Roy Binary Arithmetic Operations 12 / 13
Thank You
Dr. Shirshendu Roy Binary Arithmetic Operations 13 / 13

Binary Arithmetic Operations

  • 1.
    Binary Arithmetic Operations Presentedby Dr. Shirshendu Roy Homepage - https://digitalsystemdesign.in/ Course - Digital Electronics Dr. Shirshendu Roy Binary Arithmetic Operations 1 / 13
  • 2.
    Binary Addition Value ofa binary digit is either ’0’ or ’1’. Thus addition of two binary digits can be greater than one bit. Addition of two binary bits is shown below. 0 0 0 0 + 0 1 1 0 + 1 0 1 0 + 1 1 0 1 + Sum Carry Sum Carry Sum Carry Sum Carry In binary addition, when both the digits are ’1’ then addition result is greater than 1 bit. The extra bit is called as Carry. In this situation, Carry is generated. Dr. Shirshendu Roy Binary Arithmetic Operations 2 / 13
  • 3.
    Addition of ThreeBits 0 0 0 0 + 0 1 1 0 + 0 0 1 0 + 0 1 0 1 + Sum Carry Sum Carry Sum Carry Sum Carry 0 0 1 1 1 0 1 0 + 1 1 0 1 + 1 0 0 1 + 1 1 1 1 + Sum Carry Sum Carry Sum Carry Sum Carry 0 0 1 1 A B C Dr. Shirshendu Roy Binary Arithmetic Operations 3 / 13
  • 4.
    Binary Subtraction Thus subtractionof two binary digits can not be greater than one bit. Sub- traction of two binary bits is shown below. 0 0 0 0 1 1 - 1 0 1 1 1 0 Difference 1 Borrow Difference Difference Difference - 0 Borrow - 0 Borrow - 0 Borrow In binary subtraction, bit ’1’ can not be subtracted from bit ’0’. Thus to do this subtraction extra bit ’1’ is borrowed. The extra bit is called as Borrow. Dr. Shirshendu Roy Binary Arithmetic Operations 4 / 13
  • 5.
    Subtraction Operation forThree Bits (A − B − C) 0 0 0 - 0 1 1 - 0 0 1 - 0 1 0 - 0 0 1 1 1 0 1 - 1 1 0 - 1 0 0 - 1 1 1 - 0 0 1 1 1 Borrow A B C Difference Difference Difference Difference Difference Difference Difference Difference 0 Borrow 1 Borrow 1 Borrow 1 Borrow 0 Borrow 0 Borrow 0 Borrow Dr. Shirshendu Roy Binary Arithmetic Operations 5 / 13
  • 6.
    Strategy for SubtractionOperation fo 3-bits The subtraction operation for 3-bits is A − B − C = A − (B + C) First, B + C is evaluated and the result is subtracted from A. An example is shown below 1 1 - 0 A B C ? 1 0 A (B+C) ? 0 - Subtraction Not Possible (A < (B + C)) 1 0 A (B+C) 0 - 1 Borrow 0 Difference Dr. Shirshendu Roy Binary Arithmetic Operations 6 / 13
  • 7.
    Addition/Subtraction using One’sComplement There is no subtraction operation in One’s Complement Number System. Only addition operation is carried out. In the operation (X − Y ), X is added to −Y (represented in One’s Com- plement Number System). In this case, the result can be written like X + (2n − ulp) − Y = (2n − ulp) + (X − Y ) (1) where ulp = 20 = 1. This can be explained below with the value of n = 8 X + (256 − 1) − Y = 255 + (X − Y ) (2) Example: X = 5, Y = 6 then find X − Y for n = 8. In this case, the result is 28 − 1 + X − Y = 256 + 5 − 6 = 254. Here, 254 is one’s complement representation of −1. Dr. Shirshendu Roy Binary Arithmetic Operations 7 / 13
  • 8.
    Addition/Subtraction Example inOne’s Complement 0 0 1 1 0 1 1 0 1 1 0 1 0 1 1 1 + 0 1 0 1 1 0 0 0 0 1 1 1 0 1 1 1 (54)10 (−40)10 (13)10 A B Carry Cout 0 1 1 0 0 1 0 0 1 0 0 1 0 1 0 0 0 + 0 1 0 0 0 1 1 1 1 0 0 0 1 0 0 0 (−54)10 (40)10 (−14)10 A B Carry Sum 0 Cin Cin Cout 0 0 1 1 0 1 1 0 + 0 0 1 1 1 0 0 1 0 0 0 0 0 0 1 0 (54)10 (94)10 A B Carry Sum Cout 0 1 1 0 0 1 0 0 1 + 1 0 0 0 0 0 1 0 1 1 1 1 1 1 0 1 (−54)10 (−14)90 A B Carry 0 Cin Cin 0 0 1 0 1 0 0 0 (40)10 1 1 0 1 0 1 1 1 (−40)10 1 + 0 1 1 1 0 0 0 0 (14)10 Sum Cout 1 + 1 0 0 0 0 1 0 1 (−94)10 Sum Initially Cin = 0. A correction step is required whenever Cout bit is ’1’. In the correction step, this bit is added to the result at LSB position. Dr. Shirshendu Roy Binary Arithmetic Operations 8 / 13
  • 9.
    Addition/Subtraction using Two’sComplement There is also no subtraction operation in Two’s Complement Number System. Only addition operation is carried out. In the operation (X − Y ), X is added to −Y (represented in Two’s Com- plement Number System). In this case, the result can be written like X + 2n − Y = 2n + (X − Y ) (3) Example: X = 5, Y = 6 then find X − Y for n = 8. In this case, the result is 28 + X − Y = 256 + 5 − 6 = 255. Here, 255 is two’s complement representation of −1. Dr. Shirshendu Roy Binary Arithmetic Operations 9 / 13
  • 10.
    Addition/Subtraction Example inTwo’s Complement 0 0 1 1 0 1 1 0 1 1 0 1 1 0 0 0 + 0 0 1 1 1 0 0 0 0 1 0 0 1 1 1 1 (54)10 (−40)10 (14)10 A B Carry Sum Cout 0 1 1 0 0 1 0 1 0 0 0 1 0 1 0 0 0 + 0 0 1 0 0 1 1 1 1 0 0 0 1 0 0 0 (−54)10 (40)10 (−14)10 A B Carry Sum 0 Cin Cin Cout 0 0 1 1 0 1 1 0 + 0 0 1 1 1 0 0 1 0 0 0 0 0 0 1 0 (54)10 (94)10 A B Carry Sum Cout 0 1 1 0 0 1 0 1 0 + 0 0 1 0 0 0 1 0 1 1 0 0 1 1 0 1 (−54)10 (−14)90 A B Carry Sum 0 Cin Cin Cout 0 0 1 0 1 0 0 0 (40)10 1 1 0 1 1 0 0 0 (−40)10 Initially Cin = 0. Here, no correction step is required. Cout bit indicates only overflow condition. Dr. Shirshendu Roy Binary Arithmetic Operations 10 / 13
  • 11.
    Binary Multiplication Multiplication betweentwo binary numbers A = A2A1A0 and B = B2B1B0 can be written as S = A0 × (B2 × 22 + B1 × 21 + B0 × 20 ) + A1 × (B2 × 22 + B1 × 21 + B0 × 20 ) + A2 × (B2 × 22 + B1 × 21 + B0 × 20 ) (4) 1 0 0 1 0 1 1 0 0 1 × 1 0 0 1 0 1 × 0 0 0 0 0 0 × 0 0 0 0 0 0 1 0 0 1 0 1 × × × × 0 0 1 1 0 1 1 0 1 0 (333)10 (37)10 (09)10 1 0 0 1 0 1 1 0 0 1 × 1 0 0 1 0 1 × 0 0 0 0 0 0 × 0 0 0 0 0 0 1 0 0 1 0 1 × × × × 0 0 1 1 0 1 1 0 1 0 (2.6015)10 (2.3125)10 (1.125)10 In binary multiplication, if A has n bits and B has m bits then the multipli- cation result will have n + m + 1 bits. If n bits and m bits are used to represent fractional part in A and B respec- tively then m+n bits will be reserved for fractional part in the multiplication result. Dr. Shirshendu Roy Binary Arithmetic Operations 11 / 13
  • 12.
    Binary Division The basicequation of a division operation is N = Q.D + R = Q3.23 .D + Q2.22 .D + Q1.21 .D + Q0.20 .D + R (5) Here, N is the numerator, D is the denominator, Q is the quotient and R is the residual. The division operation shown above is for 4-bit Quotient width. 1 1 0 0 1 1 0 1 1 0 1 1 0 1 − 1 0 0 0 1 1 0 1 − 0 0 0 0 0 1 1 1 0 1 0 0 0 0 0 1 1 0 0 1 0 1 0 0 1 1 0 0 1 0 0 0 0 1 1 0 0 1 1 0 0 0 1 0 0 1 0 0 1 1 0 1 Q D R N Dr. Shirshendu Roy Binary Arithmetic Operations 12 / 13
  • 13.
    Thank You Dr. ShirshenduRoy Binary Arithmetic Operations 13 / 13