Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

EE2202 Introduction to Electronic Engineering

Chapter 6: Binary Arithmetic

A binary number can have only two values, 1 or 0. When we do binary arithmetic we have to
follow a conventional set of rules that govern the manipulation of the binary numbers. The
normal way to understand the set of rules is through a Truth Table, which will contain all possible
values that the binary numbers can take.

Addition
The rule that applies when adding two binary numbers is that if the sum exceeds 1, then you must
carry 1 to the next most significant column as a carry in, for example 1 + 1 = 10 (the 1 in 10 is the
carry in bit). With this rule the Truth Table for adding two binary numbers A and B, both of
which can take values 1 and 0 is shown below.

Truth Table for adding two binary numbers


A B SUM Carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
The Truth Table when there is a Carry in when adding two binary numbers.
A B Carry in SUM Carry out
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1

Example 1: Add 5 + 2 Example 2: Add 8 + 3


5= 0000 0101 8= 0000 1000
2= 0000 0010 + 3= 0000 0011 +
0000 0111 = 710 0000 1011 = 1110

Example 3: Add 18 + 2 Example 4: Add 147 + 75


18 = 0001 0010 147 = 1001 0011
2 = 0000 0010 + 75 = 0100 1011 +
0001 0100 = 2010 1101 1110 = 22210

Example 5: Add 31 +7
31 = 0001 1111
7 = 0000 0111 +
0010 0110 = 3810

1|Page

EE2202 Introduction to Electronic Engineering [2017] Department of Electrical and Information Engineering
Subtraction
The rule that applies when subtracting two binary numbers is that if the difference is -1, then you
must borrow 1 from the next most significant column as a borrow in.. With this rule the Truth
Table for subtracting two binary numbers A and B, both of which can take values 1 and 0 is
shown below.
Truth Table for subtracting two binary numbers
A B Remainder Borrow in
0 0 0 0
0 1 1 1
1 0 1 0
1 1 0 0
The Truth Table when there is a Borrow in when subtracting two binary numbers.
A B Borrow in Remainder Borrow out
0 0 0 0 0
0 0 1 1 1
0 1 0 1 1
0 1 1 0 1
1 0 0 1 0
1 0 1 0 0
1 1 0 0 0
1 1 1 1 1

Example 1: Subtract 27 - 10 Example 2: Subtract 9 - 4


27 = 0001 1011 9= 0000 1001
10 = 0000 1010 - 4= 0000 0100 -
0001 0001 = 1710 0000 0101 = 510

Example 3: Subtract 172 - 42


172 = 1010 1100
42 = 0010 1010 -
1000 0010 = 13010

Multiplication
Example: Multiply 13 x 11
13 = 0000 1101
11 = 0000 1011 x
0000 1101
00001 101
000000 00
0000110 1
1000 1111 = 14310
Division
Example 1: Divide 135 / 15
135 = 1000 0111
15 = 0000 1111

2|Page

EE2202 Introduction to Electronic Engineering [2017] Department of Electrical and Information Engineering
1001 = 910
00001111 10000111
-1111
1111
-1111
0

Example 2: Divide 35 / 5
35 = 0010 0011
5 = 0000 0101
111 = 710
00000101 00100011
- 101
111
-101
101
-101
0
The binary arithmetic functions we have considered are for positive integers.

2’s Complement
In 2’s complement both +ve and -ve numbers can be represented. The MSB or the leftmost bit
signifies whether the number is +ve or –ve, and is called the sign bit. The sign bit is 0 for +ve
numbers and 1 for –ve numbers.
In a 8 bit system
Range of +ve numbers are 0000 0000 to 0111 1111 (0 to 127).
Range of –ve numbers are 1111 1111 to 1000 0000 (-1 to -128)
Generally, if N is the maximum number of bits in the system,
The maximum +ve number that can be represented is 2N-1 -1
The maximum –ve number that can be represented is -2N-1

As an example, the decimal +710 to -810 values and there 2’s complement are given below.
Decimal 2’s Complement
+7 0000 0111
+6 0000 0110
+5 0000 0101
:
+1 0000 0001
0 0000 0000
-1 1111 1111
-2 1111 1110
-3 1111 1101
:
-7 1111 1001
-8 1111 1000

3|Page

EE2202 Introduction to Electronic Engineering [2017] Department of Electrical and Information Engineering
Rules for Decimal to 2’s complement conversion
1. If decimal number is +ve, 2’s complement is the true binary number
2. If decimal number is –ve, to get 2’s complement,
a) complement each bit of binary equivalent (change the 0’s to 1 and
1’s to 0). This is called the 1’s complement
b) Add 1 to 1’s complement number

Rule’s for 2’s Complement to decimal conversion


1. If 2’s complement is +ve (sign bit = 0), the regular binary to decimal conversion
2. If 2’ complement is –ve (sign bit = 1), decimal number is –ve and given by, a) complement
the entire 2’s complement, bit by bit
b) add 1 to get binary equivalent
c) regular binary to decimal conversion to get decimal value.

Example 1: Convert +3510 to 2’ complement


Binary value 0010 0011
2’s complement 0010 0011
Number is +ve, MSB is 0

Example 2: Convert -3510 to 2’s complement


Binary of 35 0010 0011
1’s complement 1101 1100
Add 1 +1
2’s complement 1101 1101
Sign bit is 1, Number is -ve
Example 3: Convert -9810 to 2’s complement
Binary of 98 0110 0010
1’s complement 1001 1101
Add 1 +1
2’s complement 1001 1110
Sign bit is 1, Number is -ve
Example 4: Convert 1101 1101 2’s complement to decimal
Note: sign bit is 1 so decimal number is -ve
2’s complement 1101 1101
1’s complement 0010 0010
Add 1 +1
Binary value 0010 0011 = -3510 as Sign bit is 1
Example 5: Convert 1011 0010 2’s complement to decimal
Note: sign bit is 1 so decimal number is -ve
2’s complement 1011 0010
1’s complement 0100 1101
Add 1 +1
Binary value 0100 1110 = -7810 as Sign bit is 1

2’s Complement Arithmetic


Adding 2 numbers: Normal binary addition A + B
Subtracting two numbers: Convert subtraction number as A – B = A + (-B)
Note that for a 8 bit system decimal values cannot exceed +127 to -128
for a 16 bit system decimal values cannot exceed +32,767 to -32,768

4|Page

EE2202 Introduction to Electronic Engineering [2017] Department of Electrical and Information Engineering
Example 1: Add 19 + 27 using 8 bit 2’s complement
19 = 0001 0011
27 = 0001 1011+
0010 1110 = 4610
Example 2: Subtract 18 – 7using 2’ complement
18 = 0001 0010
-7 = 1111 1001+
0000 1011 = 1110
 Carry out of the MSB is ignored. This always occurs for +ve sums

Example 3: Subtract 21 -12 using 2’s complement


21= 0001 0101
-12= 1111 0100+
0000 1000 = 810

Example 4: Subtract 118 – 54 using 2’s complement


118 = 0111 0110
-54 = 1100 1010+
0100 0000 = 6410

Example 5: Subtract 59 – 96 using 2’s complement


59 = 0011 1011
-96 = 1010 0000+
1101 1011 = - 3710

5|Page

EE2202 Introduction to Electronic Engineering [2017] Department of Electrical and Information Engineering

You might also like