Professional Documents
Culture Documents
Chapter 6
Chapter 6
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.
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
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
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
5|Page
EE2202 Introduction to Electronic Engineering [2017] Department of Electrical and Information Engineering