Lecture 2: Number Systems and Codes: Youssef Jaffal
Lecture 2: Number Systems and Codes: Youssef Jaffal
Youssef Jaffal
Phoenicia University
Electrical & Communication Engineering
EENG 212: Digital System Design
The figures in this presentation are taken from “Wakerly, Digital Design: Principles and Practices, 4th
edition.”
1/22
Youssef Jaffal Lecture 2: Number Systems and Codes
Introduction
2/22
Youssef Jaffal Lecture 2: Number Systems and Codes
Positional Number Systems
A number is represented by a string of digits
Each digit position has an associated weight
The value of a number is a weighted sum of the digits
Ex1: 1734 = 1 × 1000 + 7 × 100 + 3 × 10 + 4 × 1
The weights are power of 10: 1000, 100, 10, 1
Ex2: 85.68 = 8 × 10 + 5 × 1 + 6 × 0.1 + 8 × 0.01
We have positive and negative powers
This system had a base (radix, r) of 10
General form of a number is:
3/22
Youssef Jaffal Lecture 2: Number Systems and Codes
Positional Number Systems
Binary: radix = 2
Digital circuits have signals that are normally in one of only
two conditions; low or high, charged or discharged, off or on.
Binary is used to represent numbers in a digital system
Ex: 110.012 = 1 × 4 + 1 × 2 + 0 × 1 + 0 × 0.5 + 1 × 0.25 = 6.2510
In general the value is given by:
p−1
B= ∑ bi 2i
i=−n
Ex1: 1CE8.116 =
1 × 163 + 12 × 162 + 14 × 16 + 8 × 1 + 1 × 16−1 = 7400.062510
5/22
Youssef Jaffal Lecture 2: Number Systems and Codes
General Positional Number System Conversions
6/22
Youssef Jaffal Lecture 2: Number Systems and Codes
General Positional Number System Conversions
Decimal fraction to binary: It is done by successive
multiplications taking out each time the integer part of the
result.
Example: convert 0.3125 to binary
0.3125 × 2 = 0.625 →0
0.625 × 2 = 1.25 →1
0.25 × 2 = 0.5 →0
0.5 × 2 = 1 →1 (LSB)
7/22
Youssef Jaffal Lecture 2: Number Systems and Codes
General Positional Number System Conversions
Binary to Octal: Bits are grouped in “Threes” from right to
left, and the binary value of every group represents the
corresponding Octal Digit
Example
8/22
Youssef Jaffal Lecture 2: Number Systems and Codes
Addition of Binary Numbers
Example
9/22
Youssef Jaffal Lecture 2: Number Systems and Codes
Subtraction of Binary Numbers
Example
10/22
Youssef Jaffal Lecture 2: Number Systems and Codes
Representation of Negative Numbers
11/22
Youssef Jaffal Lecture 2: Number Systems and Codes
Complements
(rn − 1) − N
12/22
Youssef Jaffal Lecture 2: Number Systems and Codes
Complements
(r − 1)’s complement = (rn − 1) − N
Ex: r = 10, what is 10n ?
It is a single ‘1’ followed by n 0s. Ex: 104 = 1000010
Ex: r = 10, what is 10n − 1?
It is n 9s. 104 − 1 = 9999
What is 9’s complement of 546700?
106 − 1 − 546700 = 999999 − 546700 = 453299
Since rn − N = [(rn − 1) − N] + 1
r’s complement is obtained by taking (r − 1)’s complement and
adding 1.
Ex1: 2’s complement of 101100 is
010011 + 1 = 010100
14/22
Youssef Jaffal Lecture 2: Number Systems and Codes
Complements
Short cuts:
10’s complement: leave all least significant 0s unchanged,
subtract first nonzero least significant digit from 10, and
subtract all higher significant digits from 9.
Ex: 10’s complement of 012398 is 987602
15/22
Youssef Jaffal Lecture 2: Number Systems and Codes
Representation of Negative Numbers
000010012 = +910 = 20 + 23
111101112 = −910 = 20 + 21 + 22 + 24 + 25 + 26 −27
16/22
Youssef Jaffal Lecture 2: Number Systems and Codes
Representation of Negative Numbers
17/22
Youssef Jaffal Lecture 2: Number Systems and Codes
2’s Complement Addition: Overflow
20/22
Youssef Jaffal Lecture 2: Number Systems and Codes
Binary Codes for decimal Numbers
Gray Code
Only 1 bit changes between each pair of consecutive codewords
It is a reflective code
For a 1-bit code: 0 and 1
For (N + 1) bit code, the first 2N are the same of N-bit code
with a leading 0
The last 2N are the reverse of N-bit code with a leading 1
21/22
Youssef Jaffal Lecture 2: Number Systems and Codes
Binary Codes for decimal Numbers
Gray Code, Example
Figure taken from mathworks.com
22/22
Youssef Jaffal Lecture 2: Number Systems and Codes