Computer Architecture and
Computer Architecture and
Organization
Organization
Chapter 3: Data Representation
Decimal to Binary Conversion – Fixed Point Numbers
Decimal to Binary Conversion – Fixed Point Numbers
Converting the Fractional Part —The Multiplication Method
A binary fraction is represented in the general form:
b–1 X 2 –1 + b
–2 X 2 –2 + b–3 X 2 –3 + . . .
If we multiply the fraction by 2, then we will obtain:
b–1 + b–2 X 2 –1 + b
–3 X 2 –2 + . . .
Decimal to Binary Conversion – Fixed Point Numbers
Decimal to Binary Conversion – Fixed Point Numbers
Remainder Method:
Conversion of the
decimal number 1234 to binary by
successive halving, starting at the top and working downward. For example, 77
divided by 2 yields a quotient of 38 and a remainder of 1
Quotient Remainder 1234 617 308 77 38 19 154 2 4 9 1 0 1 0 1 1 0 0 0 1 0 1 0
1 0 0 1 1 0 1 0 0 1 0
Decimal to Binary Conversion – Fixed Point Numbers
Decimal to Binary Conversion – Fixed Point Numbers
Converting the Fractional Part —The Multiplication Method
.375 X 2 = 0.75
.75 X 2 = 1.5
.5 X 2 = 1.0
(0.375)10 = (.011)2
Most significant bit
Decimal to Binary Conversion –
Decimal to Binary Conversion –
Fixed Point Numbers
Fixed Point Numbers
Converting the Fractional Part —
The Multiplication Method
Terminating Fraction
Terminating Fraction
Mixed Fraction
Mixed Fraction
Check by converting back to Decimal
Binary to Decimal Conversion
Binary to Decimal Conversion
Conversion of the binary number 101011011 to decimal by
101011011
1 X 20 = 1
1 X 23 = 8
1 X 24 = 16
0 X 25 = 0
1 X 26 = 64
0 X 27 = 0
1 X 28 = 256
1 X 21 = 2
0 X 22 = 0
34710
Binary, Octal, and Hexadecimal Radix Representations
Decimal (Base 10)
Decimal (Base 10) Binary (Base 2)Binary (Base 2) Octal (Base 8)Octal (Base 8) Hexadecimal (Base 16)Hexadecimal (Base 16) 0
0 00 00 00
1
1 11 11 11
2
2 1010 22 22
3
3 1111 33 33
4
4 100100 44 44
5
5 101101 55 55
6
6 110110 66 66
7
7 111111 77 77
8
8 10001000 1010 88
9
9 10011001 1111 99
10
10 10101010 1212 AA
11
11 10111011 1313 BB
12
12 11001100 1414 CC
13
13 11011101 1515 DD
14
14 11101110 1616 EE
15
Representing Negative Numbers
Representing Negative Numbers
Signed magnitude
Signed magnitude
One’s complement
One’s complement
Note that: Both Signed magnitude and one’s
Note that: Both Signed magnitude and one’s
complement have two representation for
complement have two representation for
zero: a plus zero and a minus zero
zero: a plus zero and a minus zero
Two’s complement
Two’s complement
Excess 2m – 1 – Examples: for an eight bit
Excess 2m – 1 – Examples: for an eight bit
number, 0 becomes 128 + 0 = 128, 1
number, 0 becomes 128 + 0 = 128, 1
becomes 1 + 128 = 129, -5 becomes -5 +
becomes 1 + 128 = 129, -5 becomes -5 +
Negative Binary Numbers – 8 bits
Negative Binary Numbers – 8 bits
N N Decimal Decimal N N Binary Binary -N Signed -N Signed Magnitude
Magnitude -N 1’s -N 1’s
Complement
Complement -N 2’s
-N 2’s
Complement
Complement -N excess
-N excess
128
Binary Arithmetic
Binary Arithmetic
Binary Arithmetic
Binary Arithmetic
• Addition
– 1’s Complement – 2’s Complement • Subtraction
– Use addition – add the complement of the subtrahend to the minuend
– Both are complement form, just add them together. • Overflow
– If the addend and augend are of opposite signs, overflow error cannot occur. If they are of the same sign and the
Floating Point Numbers
Floating Point Numbers
n = f X 10
e
Radix
Exponent
Floating-Point Numbers
Floating-Point Numbers
3.14 = 0.314 × 101 = 3.14 × 100 0.000001 = 0.1 × 10-5 = 1.0 × 10-6 1941 = 0.1941 × 104 = 1.941 × 103
Consider a number representation:
• A signed three-digit fraction range in magnitude from 0.1 ≤ |f| < 1 or zero and a signed two-digit exponent has the negative number range:
from -0.100 × 10-99 to -0.999 × 10+99 and positive number range
Floating-Point Numbers
Floating-Point Numbers
• Large negative number less than -0.999 × 1099
• Negative number between -0.999 × 1099 and -0.100 × 10-99
• Small negative number with magnitudes less than 0.100 × 10-99
• Zero
• Small positive number with magnitudes less than 0.100 × 10-99
• Positive numbers between 0.100 × 10-99 and 0.999 × 1099
• Large positive numbers greater than 0.999 × 10+99
Total of 358,201 distinct numbers (179,100 positive, 179,100 negative, and one 0) over the range between -0.999×1099 to 0.999×1099
What are these numbers?
Floating-Point Numbers
Floating-Point Numbers
• Overflow – the magnitude is too large to be represented by it’s positive exponent value (for both + and - numbers)
• Underflow – the magnitude is too small to be represented by it’s negative exponent value (for both + and - numbers) • In many cases the underflow error is less serious than the overflow error.
• Fraction (mantissa) represent the density between two real numbers. Increasing the fraction increases the accuracy. • Exponent represent the size (scope) of the number.
IEEE 754 Floating-Point
IEEE 754 Floating-Point
• Single precision – 32 bits • Double precision – 64 bits • Extended precision – 80 bits • Starting from the leftmost bits
– Sign; Exponent, 8 for single (excess 127) and 11 for double (excess 1023); Fraction, 23 for single and 52 for double.
IEEE 754 Floating-Point
IEEE 754 Floating-Point
Floating Point Operations
Floating Point Operations
•
•
Addition/subtraction
Addition/subtraction
–
–
Align the exponent
Align the exponent
–
–
Add (subtract) the mantissa
Add (subtract) the mantissa
–
–
Normalize the result
Normalize the result
•
•
Multiplication (division)
Multiplication (division)
–
–
Multiply (divide) the mantissa
Multiply (divide) the mantissa
–
–
Add the exponent (subtract)
Add the exponent (subtract)
–
References
References
http://www.acs.ilstu.edu/faculty/cjong/Sprin
g2006/ITK225/ClassNotes
William Stallings, Computer Architecture
William Stallings, Computer Architecture
and Organization. 2000
and Organization. 2000
Miles J. Murdocca and Vincent P. Heuring.
Principles of Computer Architecture. Class
Principles of Computer Architecture. Class
Test Edition, 1999