Lecture 5 Representing Numerical Data
Lecture 5 Representing Numerical Data
1
BINARY CODED DECIMAL
BCD
Stored as a digit-by-digit binary representation of the original decimal
integer
2
VALUE RANGE
Binary: 4 bits can hold 16 different values (0 to 15)
BCD: 4 bits can hold only 10 different values (0 to 9)
3
CONVENTIONAL BINARY VS. BCD
Binary representation generally preferred
Greater range of value for given number of bits
Calculations are easier
4
EXAMPLE
5
EXPONENTIAL NOTATION
Also called Scientific Notation
6
EXPONENTIAL NOTATION
Example: 12345 × 100
4 specifications required for a number
Sign (“+” in example)
Magnitude or mantissa(12345)
Sign of the exponent (“+”)
Magnitude of the exponent (5)
Plus
Base of the exponent (10)
Location of decimal point (or other base) radix point
0.12345 x 105
123450000 x 10-4
7
FORMAT SPECIFICATION
For integers
SMMMMMMM
8
FORMAT SPECIFICATION
For floating point numbers,
9
FORMAT
Mantissa: sign-magnitude format with sign digit
Assume decimal point located at beginning of mantissa
Excess-N notation: Complementary notation
Pick middle value as offset where N is the middle value
Excess-50 notation
10
MAGNITUDE RANGE
11
OVERFLOW AND UNDERFLOW
Underflow,
The number is a decimal fraction of magnitude too small to
be stored
12
EXAMPLES
13
FLOATING POINT CALCULATIONS
Addition and subtraction
Exponent and mantissa treated separately
Exponents of numbers must agree
Align decimal points
Least significant digits may be lost
Mantissa overflow requires exponent again shifted right
14
ADDITION AND SUBTRACTION
15
ADDITION AND SUBTRACTION
16
MULTIPLICATION AND DIVISION
17
FLOATING POINT IN THE COMPUTER
4, 8, or 16 bytes can be used to represent a floating point
numbers
Typical floating point format
32 bits provide range ~10-38 to 10+38
8-bit exponent = 256 levels
Excess-128 notation
•23/24 bits of mantissa: approximately 7 decimal digits of
precision
18
FLOATING POINT IN THE COMPUTER
19
IEEE 754 STANDARD
Defines formats for 32-bit and 64-bit floating point
arithmetic
Facilitates the portability of programs between different
computers that support the standard
32 bits,
1 sign bit
8 bits exponent (2−126 to 2127)
23 bits mantissa
Normalized
20
IEEE 754 STANDARD
21
CONVERSION: BASE 10 AND BASE 2
Convert 253.7510 to binary floating point form
Multiply number by 100 => 25375
Convert to binary equivalent 110 0011 0001 1111
1.1000 1100 0111 11 x 214
22
PROGRAMMING CONSIDERATIONS
Integer advantages
Easier for the computer to perform
Potential for higher precision
Faster to execute
Fewer storage locations to save time and space
Most high-level languages provide 2 or more formats
Short integer (16 bits)
Long integer (64 bits)
23
PROGRAMMING CONSIDERATIONS
Real numbers
Variable or constant has fractional part
Numbers take on very large or very small values outside
integer range
Program should use least precision sufficient for the task
Packed decimal attractive alternative for business applications
24
THANK YOU
25
REFERNCES
Chapter 5: REPRESENTING NUMERICAL DATA -The
Architecture of Computer Hardware, Systems Software &
Networking: An Information Technology Approach -4th
Edition, Irv Englander -John Wiley and Sons
26