Professional Documents
Culture Documents
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
MSB
3
Octal
• Base = 8
• 8 digits { 0, 1, 2, 3, 4, 5, 6, 7}
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
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.
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.
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 }
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.
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.
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
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
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
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.
Signed-complement
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