0% found this document useful (0 votes)
66 views26 pages

Lecture 5 Representing Numerical Data

This document discusses different ways of representing numerical data in computers, including binary coded decimal (BCD), conventional binary, and floating point representations. It covers topics like value ranges for different representations, exponential notation, format specifications for integers and floating point numbers, overflow and underflow, basic operations on floating point numbers, and the IEEE 754 standard for floating point arithmetic. The document provides examples and comparisons of different representations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views26 pages

Lecture 5 Representing Numerical Data

This document discusses different ways of representing numerical data in computers, including binary coded decimal (BCD), conventional binary, and floating point representations. It covers topics like value ranges for different representations, exponential notation, format specifications for integers and floating point numbers, overflow and underflow, basic operations on floating point numbers, and the IEEE 754 standard for floating point arithmetic. The document provides examples and comparisons of different representations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

CS2842 Computer Systems – Lecture V

Representing Numerical Data


Dr. Sapumal Ahangama
Department of Computer Science and Engineering

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)

 BCD range of values <conventional binary representation

3
CONVENTIONAL BINARY VS. BCD
 Binary representation generally preferred
 Greater range of value for given number of bits
 Calculations are easier

 BCD often used in business applications to maintain decimal


rounding and decimal precision
 0.210 = .001100110011... (Conventional Binary)
 0.210 = 0.0010 (BCD)

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

 For floating point numbers,


 Must be divided: to sub parts
 Part of the space is reserved for the exponent and its sign
 The remainder is allocated to the mantissa and its sign
 The base of the exponent and the implied location of the binary point
are standardized as part of the format

8
FORMAT SPECIFICATION
 For floating point numbers,

 Increased range of values (two digits of exponent) traded for


decreased precision (two digits of mantissa)

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

 Larger range than the integers


 Represent fractions

11
OVERFLOW AND UNDERFLOW
 Underflow,
 The number is a decimal fraction of magnitude too small to
be stored

12
EXAMPLES

 Convert 246.8035 to floating point representation

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

You might also like