Title: CA Lecture 3: Data Representation II
1CA Lecture 3 Data Representation (II)
- Floating Point Numbers and Character Code
- (Chapter 2 of text book)
2Disadv. of fixed point number representation
- The disadvantage of fixed point numbers need a
great many digits to represent a practical range
of numbers as in practice, very large and very
small numbers can appear in any computation. E.g.
- To represent a number as large as a trillion2,
the computer needs at least 40 bits to the left
of the radix point since 240 1012.
3Disadv. of fixed point number representation
cont.
- If the same computer needs to represent one
trillionth, then 40 bits must also be maintained
on the right of the radix point. Thus 80 bits are
needed per number! - A great deal of hardware (e.g. wires) is required
to store and manipulate numbers with 80 or more
bits of precision, and the speed of computation
would also be slower.
4Floating Point Numbers
- Fine precision is generally not needed when large
numbers are used, and large numbers do not
generally need to be represented when
calculations are made with small numbers. - An efficient computer can be realized when only
as much precision is retained as is needed. - Floating point numbers allow very large and
very small numbers to be represented using only a
few digits, at the expense of precision.
5Base 10 Floating Point Numbers (FPN)
- The precision is determined by the number of
digits in the fraction 6.023 (or significand or
mantissa which has integer and fractional parts). - The range (represented by a power of 10, 1023) is
determined by the number of digits in the
exponent.
6Range and Precision in FPN
- A floating point number can be characterized by
a triple of numbers sign, exponent, and
significand. - The ordering (sign bit, exponent, then
significand) is helpful in comparing two floating
point numbers. - The range/precision trade-off is a major
advantage of using a floating point
representation.
7Normalization
- The same number can be represented in different
floating point forms - (3584.1)10 100 (3.5841)10 103
(0.35841)10 104 -
(35.841)10 102 - Floating point numbers are usually normalized,
in which the radix point is located in only one
possible position for a given number. - Usually, the normalized representation places
the radix point immediately to the left or right
of the leftmost, nonzero digit in the fraction,
as in (0.35841)10 104 or (3.5841)10 103
8Normalization and The Hidden Bit in base 2
- Number zero cannot be represented in the
normalized form. Thus zero is represented as all
0s in the mantissa/significand. - If the mantissa is represented as a binary,
then there is always a leading 1 in the
normalized mantissa, so there is no need to store
that 1. E.g. - (110.10)2 x 22 (0.11010)2 25 (1.1010)2
24 - This missing bit is referred to as the hidden
bit, also known as a hidden 1.
9Hidden Bit
- For the above example
- If normalized representation places the binary
point immediately to the left of the leftmost,
nonzero digit in the fraction, then normalized
mantissa 0.11010 will be stored in bit pattern
1010. - If normalized representation places the binary
point immediately to the right of the leftmost,
nonzero digit in the fraction, then normalized
mantissa 01.1010 will be stored in bit pattern
1010.
10Representing FPN in a Computer
- Assume a computer represents floating point
numbers in this ordering of packing the sign
bit, 3-bit excess 4 exponent, 3 hexadecimal (base
16) digits of significand. - The normalized form places the radix point
immediately to the left of the leftmost , nonzero
digit in the fraction. - The hexadecimal point will NOT be stored.
- Consider representing (358.0)10 in this format.
- 1st step convert the fixed point number from its
original base into a fixed point number in the
target base (base 16). Thus (358.0)10 (166.0)16
11Representing FPN in The Computer Cont.
- 2nd step normalize the number. Thus
- (166.)16 X 160 (.166)16 X 163
- 3rd step convert mantissa into a binary
pattern. (166)16 (0001 0110 0110)2 - 4th step work out the exponent in excess 4 gt
(3 4 7)10 (111)2 - 5th step fill in the bit fields, with a
positive sign (sign bit 0), and the rest - 0 111 . 0001 0110 0110
12Another floating point example
13Another floating point example cont.
14Reason for the use of excess 4 exponent in FPR
- The use of an excess 4 exponent instead of a 2s
complement or a signed magnitude exponent
simplifies comparison, addition and subtraction
of floating point numbers. - FPN arithmetic will be covered in the next
lecture.
15The IEEE 754 Floating Point Standard
- IEEE stands for Institute of Electrical and
Electronics Engineers. - The IEEE 754 is an international standard for
floating point numbers. - The IEEE 754 standard must be supported by a
computer system. - The IEEE 754 standard can be supported by the
hardware entirely, or can be supported by a
mixture of hardware and software.
16The IEEE 754 Cont.
- There are two primary formats in the IEEE 754
standard single precision and double precision. - Both single and double formats are in base 2.
- Uses hidden bit.
- The single-precision format occupies 32 bits.
- The double-precision format occupies 64 bits.
- Normalization binary point is on the right
side of the leftmost non-zero digit.
17The IEEE 754 Cont.
18Single Precision Format
- The sign bit is on the leftmost position and
indicates a positive or negative number for a 0
or a 1, respectively. - The 8-bit excess 127 exponent follows. Bit
patterns 00000000 and 11111111 are reserved for
special cases. - The 23-bit base 2 fraction follows.
- A hidden bit is to the left of the binary
point. Totally there are 12324-bit significand.
19Double Precision Format
- The sign bit is the same as in SPF.
- The 11-bit excess 1023 exponent follows. Again,
all 0s and all 1s are reserved for special
cases. - The 52-bit base 2 fraction follows.
- A hidden bit is to the left of the binary
point. Totally there are 15253-bit significand. - The number is normalised unless denormalised
numbers are supported.
20The IEEE 754 - Cont.
- A so-called clean zero is represented by the
reserved bit pattern 00000000 in the exponent and
all 0s in the fraction. The sign bit can be 0 or
1. Thus there are 2 representations for zero. - Infinity has a representation in which the
exponent contains the reserved bit pattern
11111111, the fraction contains all 0s, and the
sign bit can be 0 or 1. - A zero number divided by a zero will produce
NaN (Not a number). - In a NaN, the exponent contains the reserved
bit pattern 11111111, the fraction is nonzero,
and the sign bit can be 0 or 1.
21IEEE-754 Examples
22IEEE-754 Conversion Example
- Represent -12.62510 in single precision
IEEE-754 format. - Step 1 Convert to target base. -12.62510
-1100.1012 - Step 2 Normalize. -1100.1012 -1.1001012 X
23 - Step 3 Fill in bit fields. Sign is negative,
so sign bit is 1. Exponent is in excess 127 (not
excess 128!), so exponent is represented as the
unsigned integer 3 127 130. Leading 1 of
significand is hidden, so final bit pattern is - 1 1000 0010 . 1001 0100 0000 0000 0000 000
23The ASCII Character Set
- The American Standard Code for Information
Interchange (ASCII) is a 7-bit code, commonly
stored in 8-bit bytes. - The characters in positions 00-1F and position
7F are special control characters.
24The ASCII Character Set
25The Unicode Character Set
- Unicode is a 16-bit coding.
- Unicode supports a great breadth of the worlds
character sets. - Unicode is an evolving (or changing) standard.
26The Unicode Character Set
27Tutorial Two Questions
- 1. For the following single-precision IEEE 754
bit patterns show the numerical value as a base 2
significand with an exponent - (a) 0 10000011 01100000000000000000000
- (b) 1 10000000 00000000000000000000000
- (c) 1 00000000 00000000000000000000000
- (d) 1 11111111 00000000000000000000000
- (e) 0 11111111 11010000000000000000000
- (f) 0 00000001 10010000000000000000000
28Tutorial Two Questions
- 2. Convert the following decimal numbers to IEEE
single-precision floating point - 128
- -32.75
- 18.125
- 0.0625
3. A hidden 1 representation will not work for
base 16. Why not?
29Tutorial Two Questions
- 4. Consider a system with the following
floating point format 1 sign bit, followed by a
3-bit exponent, followed by a 4-bit mantissa. The
exponent is in twos complement. The magnitude of
the mantissa is a fixed point number, with a
hidden bit. Answer the following questions for
this number system, giving answers in
conventional decimal form - 4a) What is the largest possible exponent?
- 4b) What is the largest possible mantissa if
the hidden 1 is to the left of the binary point?
30Tutorial Two Questions
- 4c) What is the smallest positive normalized
mantissa if the hidden 1 is to the left of the
binary point? - 4d) What is the smallest positive normalized
mantissa if the hidden 1 is to the right of the
binary point? - 4e) What is the smallest positive number in
this system if the hidden 1 is to the left of the
binary point? - 4f) How many different numbers can be
represented by the system?
31Tutorial Two Questions
- The IBM short floating point representation uses
base 8, one sign bit, a seven-bit excess 64
exponent, and a normalized 24-bit fraction.
(Normalisation the point is on the left side of
the leftmost non-zero digit.) - 5a. Represent (14.3)6 in this notation.
- 5b. What number is represented by the following
bit pattern? - 1 0111111 01110000 00000000 00000000
- Show your answer in decimal. Note The spaces
are included in the number for readability only.