You are on page 1of 25

Faculty of Engineering and Technology

Electrical Engineering Department

EED220: Logic Design

Lecture 2
Numbers Systems
Mostafa Salah, Ph.D.
mostafa.abdulkhalek@fue.edu.eg
Contents
• Number Base-Conversion
• Complement of Numbers
• Binary Arithmetic
• Subtraction with Complements
• Signed Binary Number
• Number Representations
• Fixed Point
• Floating Point
• Binary Codes

2
Number-Base Conversion
Decimal to Binary: The conversion is accomplished through division by 2
Successive divisionby 2:
• If the remainder is 0, the coefficient is 0
• If the remainder is 0.5, the coefficient is 1
LSB

Example. Convert decimal 41 to binary

MSB

3
Octal
• Base = 8
• 8 digits { 0, 1, 2, 3, 4, 5, 6, 7}

• Weights 64 8 1 1/8 1/64

• Weight = (Base) Position 1 4 5 7 7


2 1 0 -1 -2
• Magnitude 1 *82+ 4 *81+ 5 *80+ 7 *8-1+ 7 *8-2
• Sum of “Digit x Weight”
=(101.984375)10

• Formal Notation (145.77)8

4
Number-Base Conversion
Decimal to Octal: The conversion is accomplished through division by 8
Successive divisionby 8:
• If the remainder is less 8, the coefficient is reminder
• If the remainder is 0, the coefficient is 0

Example. Convert decimal 153 to octal

5
Number-Base Conversion
The conversion of a decimal fraction to binary is accomplished
by a method like that used for integers:
• Multiplication by 2 is used instead of division,
• Integers instead of remainders are accumulated.

Example. Convert (0.6875)10 to binary

6
Number-Base Conversion
The conversion of a decimal fraction to octal is accomplished
by a method like that used for integers:
• Multiplication by 8 is used instead of division,
• integers instead of remainders are accumulated.

Example. Convert (0.513)10 to octal

7
Disasters attributable to bad numerical computing
25-Feb-1991:Failure of Patriot Missile 04-June-1991:Explosion of Ariane Rocket
➢ American Patriot Missile battery in Saudi Arabia failed to ➢ Unmanned Ariane 5 rocket of the European Space Agency
intercept incoming Scud missile → The Scud struck an veered off its flight path, broke up, and exploded only 30 s
American Army barracks, killing 28 after lift-off (altitude of 3700 m) → The $500 million rocket
• Cause: “software problem” (inaccurate calculation of the time (with cargo) was on its first voyage after a decade of
since boot) development costing $7 billion
• Problem specifics: Time in tenths of second as measured by the
• Cause: “software error in the inertial reference system”
system’s internal clock was multiplied by 1/10 to get the time in
seconds • Problem specifics: A 64 bit floating point number relating to
the horizontal velocity of the rocket was being converted to a
• Internal registers were 24 bits wide 16 bit signed integer
1/10 = 0.0001 1001 1001 1001 1001 100 (chopped to 24 bits) • An SRI* software exception arose during conversion
because the 64-bit floating point number had a value
• Error ≈ 0.1100 1100  2–23 ≈ 9.5  10–8
greater than what could be represented by a 16-bit
• Error in 100-hr operation period signed integer
≈ 9.5  10–8  100  60  60  10 = 0.34 s *SRI = Système de Référence Inertielle or Inertial Reference System
• Distance traveled by Scud = (0.34 s)  (1676 m/s) ≈ 570 m
Finite Precision Can Lead to a Disaster Finite Range Can Lead to a Disaster
Source: http://www.ima.umn.edu/~arnold/disasters/disasters.html, and Computer Arithmetic, Number Representation, Parahami, UCSB
8
Number-Base Conversion
The conversion of decimal numbers with both integer and
fraction parts is done by converting the integer and the
fraction separately and then combining the two answers.
Using the results of previous Examples, we obtain:

9
Hexadecimal
• Base = 16
• 16 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F }

• Weights 256 16 1 1/16 1/256

• Weight = (Base) Position 1 E 5 7 A


2 1 0 -1 -2
• Magnitude 1 *162+14 *161+5 *160+7 *16-1+10 *16-2
• Sum of “Digit x Weight”
=(485.4765625)10

• Formal Notation (1E5.7A)16

10
Octal and Hexadecimal
• The conversion from and to binary, octal, and hexadecimal
plays an important role in digital computers, because shorter
patterns of hex characters are easier to recognize than long
patterns of 1’s and 0’s.

• Since 23 = 8 and 24 = 16,


• Each octal digit corresponds to three binary digits
• Each hexadecimal digit corresponds to four binary digits.

11
Octal and Hexadecimal Numbers
Binary to Octal
The conversion from binary to octal is easily accomplished by
partitioning the binary number into groups of three digits each, starting
from the binary point and proceeding to the left and to the right.
The corresponding octal digit is then assigned to each group. The
following example illustrates the procedure:

12
Octal and Hexadecimal Numbers
Binary to Hexadecimal
The conversion from binary to hexadecimal is easily accomplished by
partitioning the binary number into groups of four digits each, starting
from the binary point and proceeding to the left and to the right.
The corresponding hexa digit is then assigned to each group. The
following example illustrates the procedure:

13
Octal and Hexadecimal Numbers
Octal and Hexadecimal to Binary
Conversion from octal or hexadecimal to binary is done by reversing the
preceding procedure. Each octal digit is converted to its three‐digit
binary equivalent. Similarly, each hexadecimal digit is converted to its
four‐digit binary equivalent. examples:

14
Binary Arithmetic
Addition and Subtraction
• Example: • Example:
Add the two numbers 1111 and 10111 Subtract the number 100111 from
101101.
1 1 1 1  carry bits
1 1  Borrow bits
01111
+ 101101
10111 ‒
100111
100110
000110
0+0=0 0–0=0
Check (100110)2 = 38 0+1=1 0 – 1 = 1 Borrow 1
Check (000110)2 = 6
1+0=1 1–0=1
1 + 1 = 0 Carry 1 1–1=0

15
Binary Arithmetic
Addition and Subtraction
• Example: Addition • Example: Subtraction
Add the two numbers 111101 and 10111 Subtract 100101 - 10111.

1 1 1 1 1 1
1 2 = (10)2
1 1 1 1 0 1 = 61
0 2 2 0 0 2
+ 1 0 1 1 1 = 23
1 0 0 1 1 0 1 = 77
1 0 1 0 1 0 0 = 84
− 1 0 1 1 1 = 23

≥ (2)10 0 1 1 0 1 1 0 = 54

16
Complement of Numbers
• Complements are used in digital computers to simplify the subtraction
operation and for logical manipulation.
• Simplifying operations leads to simpler, less expensive circuits to implement the
operations.

• Given a number N in base r having n digits. There are two types of


complements for each base‐r system:
1. The radix complement (the r’s complement ) is defined as r n ‒ N
2. The diminished radix complement ((r ‒ 1)’s complement) is defined as (r n ‒ 1) ‒ N

The complement of the complement restores the number to its original value.

17
Complement of Numbers
10’s and 9’s Complement
1. The radix complement (the r’s complement ) is defined as r n ‒ N
2. The diminished radix complement ((r ‒ 1)’s complement) is defined as (r n ‒ 1) ‒ N

For n-digits decimal number:


• The 10’s complement is r n ‒ N
Example. For N = (246700)10 , n = 6, r = 10 → r n = 106
The 10’s complement of 246700 is 1000000 ‒ 246700 = 753300.
• The 9’s complement is (r n ‒ 1) ‒ N
Example. For N = (546700)10 , n = 6, r = 10 → (r n ‒ 1) = (106 – 1) = 999999
The 9’s complement of 546700 is 999999 ‒ 546700 = 453299.
Example. The 9’s complement of 012398 is 999999 ‒ 012398 = 987601

18
Complement of Numbers
1’s and 2’s Complement
1. The radix complement (the r’s complement ) is defined as r n ‒ N
2. The diminished radix complement ((r ‒ 1)’s complement) is defined as (r n ‒ 1) ‒ N

For n-bits binary number:


• The 1’s complement is formed by changing 1’s to 0’s and 0’s to 1’s.
Example. The 1’s complement of 1101100 is 0010011
The 1’s complement of 0110111 is 1001000

• The 2’s complement is formed by adding 1 to the 1’s complement.


Example. The 2’s complement of 1101100 is 0010100
The 2’s complement of 0110111 is 1001001

19
Subtraction with Complements
In this method, the subtraction of two n‐digit unsigned numbers M
– N in base r can be done as follows:
1. Add the minuend M to the r’s complement of the subtrahend N.
Mathematically, M + (r n – N) = M – N + r n.
2. If M ≥ N, the sum will produce an end carry r n , which can be
discarded; what is left is the result M – N .
3. If M < N, the sum does not produce an end carry and is equal to
r n – (N – M), which is the r’s complement of (N – M).
➢To obtain the answer in a familiar form, take the r’s complement of the
sum and place a negative sign in front.

20
Subtraction with Complements – 10’s Complement
Example: Using 10’s complement, subtract 72532 – 3250.
M→ 72532 Note that:
+ ➢M has five digits and N has only four digits; Both
10’s complement of N → 96750
----------------------- numbers must have the same number of digits, so
Sum → 169282 we write N as 03250.
➢ The occurrence of the end carry signifies that
Discard end carry
the result is therefore positive.
Answer → 69282

Example: Using 10’s complement, subtract 3250 – 72532


M→ 03250 Note that:
+ ➢Because we are dealing with unsigned numbers,
10’s complement of N → 27468
----------------------- there is really no way to get an unsigned result for
Sum → 30718 this case.
➢When subtracting with complements, we
No carry
recognize the negative answer from the absence
Answer is –(10’s complement of 30718 → –69282 of the end carry and the complemented result.
21
Subtraction with Complements – 2’s Complement
Example: Using 2’s complement, with X = 1010100 and Y = 1000011

subtract X – Y subtract Y – X

X→ 1010100 Y→ 1000011
+ +
2’s complement of Y → 0111101 2’s complement of X → 0101100
----------------------- -----------------------
Sum → 10010001 Sum → 1101111
Discard end carry No carry
Answer → 10001 Answer is the –(2’s complement of 1101111)→ –10001

22
Subtraction with Complements – 1’s Complement
Subtraction of unsigned numbers can also be done by means of the (r - 1)’s complement.
• Because of (r - 1)’s complement is one less than the r’s complement, the produced sum
is one less than the correct difference when an end carry occurs.
• Removing the end carry and adding 1 to the sum is referred to as an end‐around carry.

Example: Using 1’s complement, with X = 1010100 and Y = 1000011


subtract X – Y subtract Y – X
X→ 1010100 Y→ 1000011
+ +
1’s complement of Y → 0111100 1’s complement of X → 0101011
----------------------- -----------------------
Sum → 10010000 Sum → 1101110
End carry occur No carry
Answer → 10000 + 1 = 10001 Answer is the –(1’s complement of 1101110)→ –10001
23
Signed Binary Number
If positive, 0 followed by magnitude
Signed-magnitude Signed magnitude 00001001

If negative, 1 followed by magnitude


Signed magnitude 10001001
Number
Example: Number 9.
8-bit Representation If positive, leave number unchanged
Signed 1’s complement 00001001
Signed 2’s complement 00001001

Signed-complement

If negative, complement number


Signed 1’s complement 11110110
Signed 2’s complement 11110111

24
References
‒ M. Mano and M. Ciletti, Digital Design, with an introduction to the
Verilog HDL. 5th Ed. Pearson, 2013.
‒ John F. Wakerly, Digital Design: Principles and Practices. 4th Ed. Pearson,
2005.
‒ R. Katz and G. Boriello, Contemporary Logic Design. 2nd Ed. Pearson,
2005.
‒ S. Brown and Z. Vranesic , Fundamentals of Digital Logic with Verilog
Design. 3rd Ed. SEM, 2013.
‒ B. Parhami, Computer Arithmetic: Algorithms and Hardware Designs. 2nd
Ed. Oxford U. Press, 2010.

25

You might also like