0% found this document useful (0 votes)
7 views

Week 3

Uploaded by

mcopten22
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Week 3

Uploaded by

mcopten22
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 66

2.

5 Floating-Point Representation
(1 of 33)

have just presented deal with signed integer


values only.
Without modification, these formats are not
useful in scientific or business applications
that deal with real number values.
Floating-point representation solves this
problem.
2.5 Floating-Point Representation
(2 of 33)
If we are clever programmers, we can perform
floating-point calculations using any integer format.
This is called floating-point emulation, because

create programs that make it seem as if floating-


point values are being used.

specialized hardware that performs floating-point


arithmetic with no special programming required.
2.5 Floating-Point Representation
(3 of 33)
Floating-point numbers allow an arbitrary
number of decimal places to the right of the
decimal point.
For example: 0.5 0.25 = 0.125
They are often expressed in scientific notation.
For example:
0.125 = 1.25 10-1
5,000,000 = 5.0 106
2.5 Floating-Point Representation
(4 of 33)
Computers use a form of scientific notation
for floating-point representation
Numbers written in scientific notation have
three components:
2.5 Floating-Point Representation
(5 of 33)
Computer representation of a floating-point
number consists of three fixed-size fields:

This is the standard arrangement of these


fields.

thing, many people use these terms interchangeably. We use the term
2.5 Floating-Point Representation
(6 of 33)
The one-bit sign field is the sign of the stored
value.
The size of the exponent field determines the
range of values that can be represented.
The size of the significand determines the
precision of the representation.
2.5 Floating-Point Representation
(7 of 33)

to explain the concepts.


In this model:
A floating-point number is 14 bits in length.
The exponent field is 5 bits.
The significand field is 8 bits.
2.5 Floating-Point Representation
(8 of 33)
The significand is always preceded by an implied binary
point.
Thus, the significand always contains a fractional binary
value.
The exponent indicates the power of 2 by which the
significand is multiplied.
2.5 Floating-Point Representation
(9 of 33)
Example:
Express 3210 in the simplified 14-bit floating-point model.
We know that 32 is 25. So in (binary) scientific notation 32 = 1.0 x 25 =
0.1 x 26.

versus the first.


Using this information, we put 110 (= 610) in the exponent field and 1
in the significand as shown.
2.5 Floating-Point Representation
(10 of 33)
The illustrations shown
at the right are all
equivalent
representations for 32
using our simplified
model.
Not only do these
synonymous
representations waste
space, but they can also
cause confusion.
2.5 Floating-Point Representation
(11 of 33)
Another problem with our system is that we
have made no allowances for negative
exponents. We have no way to express 0.25 (=
0.012= 0.01 20 = 0.1 2-1)! (Notice that there
is no sign in the exponent field.)

All of these problems can be fixed with no changes to


our basic model.
2.5 Floating-Point Representation
(12 of 33)
To resolve the problem of synonymous forms, we
establish a rule that the first digit of the significand
must be 1, with no ones to the left of the radix point.
This process, called normalization, results in a unique
pattern for each floating-point number.
In our simple model, all significands must have
the form 0.1xxxxxxxx
For example, 4.5 = 100.1 x 20 = 1.001 x 22 =
0.1001 x 23. The last expression is correctly
normalized.
In our simple instructional model, we use no implied bits.
2.5 Floating-Point Representation
(13 of 33)
To provide for negative exponents, we will use a
biased exponent.
In our case, we have a 5-bit exponent.
25-1 1 = 24 1 = 15
Thus will use 15 for our bias: our exponent will
use excess-15 representation.
In our model, exponent values less than 15 are
negative, representing fractional numbers.
2.5 Floating-Point Representation
(15 of 33)
Example:
Express 3210 in the revised 14-bit floating-point model.
We know that 32 = 1.0 x 25 = 0.1 x 26.
To use our excess 15 biased exponent, we add 15 to
6, giving 2110 (= 101012).
So we have:
2.5 Floating-Point Representation
(15 of 33)
Example:
Express 0.062510 in the revised 14-bit floating-point
model.
We know that 0.0625 is 2-4. So in (binary) scientific
notation 0.0625 = 1.0 x 2-4 = 0.1 x 2-3.
To use our excess 15 biased exponent, we add 15 to 3,
giving 1210 (= 011002).
2.5 Floating-Point Representation
(16 of 33)
Example:
Express 26.62510 in the revised 14-bit floating-point
model.
We find 26.62510 = 11010.1012. Normalizing, we have:
26.62510 = 0.11010101 x 2 5.
To use our excess 15 biased exponent, we add 15 to 5,
giving 2010 (= 101002). We also need a 1 in the sign bit.
2.5 Floating-Point Representation
(17 of 33)
The IEEE has established a standard for
floating-point numbers.
The IEEE-754 single precision floating point
standard uses an 8-bit exponent (with a
bias of 127) and a 23-bit significand.
The IEEE-754 double precision standard
uses an 11-bit exponent (with a bias of
1023) and a 52-bit significand.
2.5 Floating-Point Representation
(18 of 33)
In both the IEEE single-precision and double-precision
floating-point standard, the significant has an implied
1 to the LEFT of the radix point.
The format for a significand using the IEEE format is:

For example, 4.5 = .1001 x 23 in IEEE format is: 4.5 =


1.001 x 22. The 1 is implied, which means it does not
need to be listed in the significand (the significand
would include only 001).
2.5 Floating-Point Representation
(19 of 33)
Example: Express 3.75 as a floating-point number using
IEEE single precision.

3.75 = 11.112 = 1.111 x 21


The bias is 127, so we add 127 + 1 = 128 (this is our exponent)
The first 1 in the significand is implied, so we have:

Since we have an implied 1 in the significand, this equates to


(1).1112 x 2 (128 127) = 1.1112 x 21 = 11.112 = 3.75.
2.5 Floating-Point Representation
(20 of 33)
Using the IEEE-754 single precision floating
point standard:
An exponent of 255 indicates a special value.
If the significand is zero, the value is infinity.

Using the double precision standard:

precision number is 2047, instead of the 255 used


by the single precision standard.
2.5 Floating-Point Representation
(21 of 33)
Both the 14-bit model that we have presented
and the IEEE-754 floating point standard allow
two representations for zero.
Zero is indicated by all zeros in the exponent and
the significand, but the sign bit can be either 0 or
1.
This is why programmers should avoid testing
a floating-point value for equality to zero.
Negative zero does not equal positive zero.
2.5 Floating-Point Representation
(22 of 33)
Floating-point addition and subtraction are
done using methods analogous to how we
perform calculations using pencil and paper.
The first thing that we do is express both
operands in the same exponential power, then
add the numbers, preserving the exponent in
the sum.
If the exponent requires adjustment, we do so
at the end of the calculation.
2.5 Floating-Point Representation
(23 of 33)
Example:
Find the sum of 1210 and 1.2510 using the 14-bit
-point model.
We find 1210 = 0.1100 x 24. And 1.2510 = 0.101 x 21 =
0.000101 x 24.

Thus, our sum is


0.110101 x 24.
2.5 Floating-Point Representation
(24 of 33)
Floating-point multiplication is also carried
out in a manner akin to how we perform
multiplication using pencil and paper.
We multiply the two operands and add
their exponents.
If the exponent requires adjustment, we do
so at the end of the calculation.
2.5 Floating-Point Representation
(25 of 33)
Example:
Find the product of 1210 and 1.2510 using the 14-bit
floating-point model.
We find 1210 = 0.1100 x 2 4. And 1.2510 = 0.101 x 21.
Thus, our product is
0.0111100 x 25 =
0.1111 x 24.
The normalized
product requires an
exponent of 1910 =
100112.
2.5 Floating-Point Representation
(26 of 33)
No matter how many bits we use in a floating-point
representation, our model must be finite.
The real number system is, of course, infinite, so
our models can give nothing more than an
approximation of a real value.
At some point, every model breaks down,
introducing errors into our calculations.
By using a greater number of bits in our model, we
can reduce these errors, but we can never totally
eliminate them.
2.5 Floating-Point Representation
(27 of 33)
Our job becomes one of reducing error, or at
least being aware of the possible magnitude of
error in our calculations.
We must also be aware that errors can
compound through repetitive arithmetic
operations.
For example, our 14-bit model cannot exactly
represent the decimal value 128.5. In binary, it
is 9 bits wide:
10000000.12 = 128.510
2.5 Floating-Point Representation
(28 of 33)
When we try to express 128.510 in our 14-bit model,
we lose the low-order bit, giving a relative error of:
128.5 128
0.39%
128.5

If we had a procedure that repetitively added 0.5 to


128.5, we would have an error of nearly 2% after only
four iterations.
2.5 Floating-Point Representation
(29 of 33)
Floating-point errors can be reduced when we
use operands that are similar in magnitude.
If we were repetitively adding 0.5 to 128.5, it
would have been better to iteratively add 0.5
to itself and then add 128.5 to this sum.
In this example, the error was caused by loss
of the low-order bit.
Loss of the high-order bit is more problematic.
2.5 Floating-Point Representation
(30 of 33)
Floating-point overflow and underflow can cause
programs to crash.
Overflow occurs when there is no room to store
the high-order bits resulting from a calculation.
Underflow occurs when a value is too small to
store, possibly resulting in division by zero.

program to crash than to have it produce incorrect, but


plausible, results.
2.5 Floating-Point Representation
(31 of 33)
When discussing floating-point numbers, it is
important to understand the terms range,
precision, and accuracy.
The range of a numeric integer format is the
difference between the largest and smallest
values that can be expressed.
Accuracy refers to how closely a numeric
representation approximates a true value.
The precision of a number indicates how much
information we have about a value.
2.5 Floating-Point Representation
(32 of 33)
Most of the time, greater precision leads to
better accuracy, but this is not always true.
For example: 3.1333 is a value of pi that is
accurate to two digits, but has 5 digits of precision.
There are other problems with floating point
numbers.
Because of truncated bits, you cannot always
assume that a particular floating point
operation is associative or distributive.
2.5 Floating-Point Representation
(33 of 33)
This means that we cannot assume:
(a + b) + c = a + (b + c) or
a*(b + c) = ab + ac
Moreover, to test a floating point value for equality
to some other number, it is best to declare a
of checking to see if floating point x is equal to 2 as
follows:

it is better to use:
if (abs(x - 2) < epsilon) then ...
(assuming we have epsilon defined correctly!)
2.6 Character Codes (1 of 6)

can be displayed in a manner that is


meaningful to people.
We also need to store the results of
calculations, and provide a means for data
input.
Thus, human-understandable characters must
be converted to computer-understandable bit
patterns using some sort of character
encoding scheme.
2.6 Character Codes (2 of 6)

As computers have evolved, character codes


have evolved.
Larger computer memories and storage
devices permit richer character codes.
The earliest computer coding systems used six
bits.
Binary-coded decimal (BCD) was one of these
early codes. It was used by IBM mainframes in
the 1950s and 1960s.
2.6 Character Codes (3 of 6)

In 1964, BCD was extended to an 8-bit code,


Extended Binary-Coded Decimal Interchange
Code (EBCDIC).
EBCDIC was one of the first widely-used
computer codes that supported upper and
lowercase alphabetic characters, in addition to
special characters, such as punctuation and
control characters.
EBCDIC and BCD are still in use by IBM
mainframes today.
2.6 Character Codes (4 of 6)

Other computer manufacturers chose the 7-


bit ASCII (American Standard Code for
Information Interchange) as a replacement for
6-bit codes.
While BCD and EBCDIC were based upon
punched card codes, ASCII was based upon
telecommunications (Telex) codes.
Until recently, ASCII was the dominant
character code outside the IBM mainframe
world.
2.6 Character Codes (5 of 6)

16-bit system that can encode the characters


of every language in the world.
The Java programming language, and some
operating systems now use Unicode as their
default character code.
The Unicode codespace is divided into six
parts. The first part is for Western alphabet
codes, including English, Greek, and Russian.
2.6 Character Codes (6 of 6)

The Unicode
codespace allocation
is shown at the right.
The lowest-numbered
Unicode characters
comprise the ASCII
code.
The highest provide
for user-defined
codes.
2.7 Error Detection and Correction
(1 of 25)
It is physically impossible for any data recording or
transmission medium to be 100% perfect 100% of
the time over its entire expected useful life.
As more bits are packed onto a square centimeter
of disk storage, as communications transmission
speeds increase, the likelihood of error increases
sometimes geometrically.
Thus, error detection and correction is critical to
accurate data transmission, storage and retrieval.
2.7 Error Detection and Correction
(2 of 25)
Check digits, appended to the end of a long
number, can provide some protection against data
input errors.
The last characters of UPC barcodes and ISBNs are
check digits.
Longer data streams require more economical and
sophisticated error detection mechanisms.
Cyclic redundancy checking (CRC) codes provide
error detection for large blocks of data.
2.7 Error Detection and Correction
(3 of 25)
Checksums and CRCs are examples of systematic
error detection.
In systematic error detection a group of error control
bits is appended to the end of the block of
transmitted data.
This group of bits is called a syndrome.
CRCs are polynomials over the modulo 2 arithmetic
field.
The mathematical theory behind modulo 2 polynomials is beyond
our scope. However, we can easily work with it without knowing
its theoretical underpinnings.
2.7 Error Detection and Correction
(4 of 25)
Modulo 2 arithmetic works like clock arithmetic.
In clock arithmetic, if we add 2 hours to 11:00, we
get 1:00.
In modulo 2 arithmetic if we add 1 to 1, we get 0.

0+0=0 0+1=1
1+0=1 1+1=0
You will fully understand why modulo 2 arithmetic is so handy
after you study digital circuits in Chapter 3.
2.7 Error Detection and Correction
(5 of 25)
Find the quotient and
remainder when 1111101
is divided by 1101 in
modulo 2 arithmetic.
As with traditional
division, we note that the
dividend is divisible once
by the divisor.
We place the divisor under
the dividend and perform
modulo 2 subtraction.
2.7 Error Detection and Correction
(6 of 25)
Find the quotient and
remainder when
1111101 is divided by
1101 in modulo 2
arithmetic.
Now we bring down the
next bit of the dividend.
We see that 00101 is not
divisible by 1101. So we
place a zero in the
quotient.
2.7 Error Detection and Correction
(7 of 25)
Find the quotient and
remainder when
1111101 is divided by
1101 in modulo 2
arithmetic.
1010 is divisible by
1101 in modulo 2.
We perform the
modulo 2 subtraction.
2.7 Error Detection and Correction
(8 of 25)
Find the quotient and
remainder when 1111101
is divided by 1101 in
modulo 2 arithmetic.
We find the quotient is
1011, and the remainder
is 0010.
This procedure is very
useful to us in calculating
CRC syndromes.

Note: The divisor in this example corresponds to a


modulo 2 polynomial: X 3 + X 2 + 1.
2.7 Error Detection and Correction
(9 of 25)
Suppose we want to transmit the
information string: 1111101.
The receiver and sender decide
to use the (arbitrary) polynomial
pattern, 1101.
The information string is shifted
left by one position less than the
number of positions in the
divisor.
The remainder is found through
modulo 2 division (at right) and
added to the information string:
1111101000 + 111 =
1111101111.
2.7 Error Detection and Correction
(10 of 25)
If no bits are lost or corrupted,
dividing the received information
string by the agreed upon pattern
will give a remainder of zero.
We see this is so in the calculation
at the right.
Real applications use longer
polynomials to cover larger
information strings.
Some of the standard
polynomials are listed in the text.
2.7 Error Detection and Correction
(11 of 25)
Data transmission errors are easy to fix once
an error is detected.
Just ask the sender to transmit the data again.
In computer memory and data storage,
however, this cannot be done.
Too often the only copy of something important is
in memory or on disk.
Thus, to provide data integrity over the long
term, error correcting codes are required.
2.7 Error Detection and Correction
(12 of 25)
Hamming codes and Reed-Solomon codes are
two important error correcting codes.
Reed-Solomon codes are particularly useful in
correcting burst errors that occur when a
series of adjacent bits are damaged.
Because CD-ROMs are easily scratched, they
employ a type of Reed-Solomon error correction.
Because the mathematics of Hamming codes
is much simpler than Reed-Solomon, we
discuss Hamming codes in detail.
2.7 Error Detection and Correction
(13 of 25)
Hamming codes are code This pair of bytes has a
words formed by adding Hamming distance of 3:
redundant check bits, or parity
bits, to a data word.
The Hamming distance
between two code words is
the number of bits in which
two code words differ.
The minimum Hamming
distance for a code is the
smallest Hamming distance
between all pairs of words in
the code.
2.7 Error Detection and Correction
(14 of 25)
The minimum Hamming distance for a code,
D(min), determines its error detecting and
error correcting capability.
For any code word, X, to be interpreted as a
different valid code word, Y, at least D(min)
single-bit errors must occur in X.
Thus, to detect k (or fewer) single-bit errors,
the code must have a Hamming distance of
D(min) = k + 1.
2.7 Error Detection and Correction
(15 of 25)
Hamming codes can detect D(min) 1 errors
and correct errors

Thus, a Hamming distance of 2k + 1 is required


to be able to correct k errors in any data word.
Hamming distance is provided by adding a
suitable number of parity bits to a data word.
2.7 Error Detection and Correction
(16 of 25)
Suppose we have a set of n-bit code words
consisting of m data bits and r (redundant) parity
bits.
Suppose also that we wish to detect and correct
one single bit error only.
An error could occur in any of the n bits, so each
code word can be associated with n invalid code
words at a Hamming distance of 1.
Therefore, we have n + 1 bit patterns for each code
word: one valid code word, and n invalid code
words.
2.7 Error Detection and Correction
(17 of 25)
Using n bits, we have 2 n possible bit patterns. We
have 2 m valid code words with r check bits (where n =
m + r).
For each valid code word, we have (n + 1) bit patterns
(1 legal and n illegal).
This gives us the inequality:
(n + 1) 2 m 2 n
Because n = m + r, we can rewrite the inequality as:
(m + r + 1) 2 m 2 m + r or (m + r + 1) 2 r
This inequality gives us a lower limit on the number of
check bits that we need in our code words.
2.7 Error Detection and Correction
(18 of 25)
Suppose we have data words of length m = 4. Then:
(4 + r + 1) 2r
implies that r must be greater than or equal to 3.
We should always use the smallest value of r that makes the
inequality true.
This means to build a code with 4-bit data words that
will correct single-bit errors, we must add 3 check
bits.
Finding the number of check bits is the hard part.
The rest is easy.
2.7 Error Detection and Correction
(19 of 25)
Suppose we have data words of length m = 8. Then:
(8 + r + 1) 2r
implies that r must be greater than or equal to 4.
This means to build a code with 8-bit data words that
will correct single-bit errors, we must add 4 check
bits, creating code words of length 12.
So how do we assign values to these check bits?
2.7 Error Detection and Correction
(20 of 25)
With code words of length 12, we observe that each of
the bits, numbered 1 though 12, can be expressed in
powers of 2. Thus:
1 = 20 5 = 22 + 20 9 = 23 + 20
2 = 21 6 = 22 + 21 10 = 23 + 21
3 = 21 + 20 7 = 22 + 21 + 20 11 = 23 + 21 + 20
4 = 22 8 = 23 12 = 23 + 22
1 (= 20) contributes to all of the odd-numbered digits.
2 (= 21) contributes to the digits, 2, 3, 6, 7, 10, and 11.
. . . And so forth . . .
We can use this idea in the creation of our check bits.
2.7 Error Detection and Correction
(21 of 25)
Using our code words of length 12, number
each bit position starting with 1 in the low-
order bit.
Each bit position corresponding to a power of
2 will be occupied by a check bit.
These check bits contain the parity of each bit
position for which it participates in the sum.
2.7 Error Detection and Correction
(22 of 25)
Since 1 (=20) contributes to the values 1, 3 , 5, 7, 9,
and 11, bit 1 will check parity over bits in these
positions.
Since 2 (= 21) contributes to the values 2, 3, 6, 7, 10,
and 11, bit 2 will check parity over these bits.
For the word 11010110, assuming even parity, we
have a value of 1 for check bit 1, and a value of 0 for
check bit 2.

What are the values for the other parity bits?


2.7 Error Detection and Correction
(23 of 25)
The completed code word is shown above.
Bit 1checks the bits 3, 5, 7, 9, and 11, so its value is 1 to
ensure even parity within this group.
Bit 4 checks the bits 5, 6, 7, and 12, so its value is 1.
Bit 8 checks the bits 9, 10, 11, and 12, so its value is
also 1.
Using the Hamming algorithm, we can not only
detect single bit errors in this code word, but also
correct them!
2.7 Error Detection and Correction
(24 of 25)
Suppose an error occurs in bit 5, as shown above.
Our parity bit values are:
Bit 1 checks 1, 3, 5, 7, 9, and 11. This is incorrect as we
have a total of 3 ones (which is not even parity).
Bit 2 checks bits 2, 3, 6, 7, 10, and 11. The parity is
correct.
Bit 4 checks bits 4, 5, 6, 7, and 12. This parity is
incorrect, as we 3 ones.
Bit 8 checks bit 8, 9, 10, 11, and 12. This parity is
correct.
2.7 Error Detection and Correction
(25 of 25)
We have erroneous parity for check bits 1 and 4.
With two
the error is in the data, and not in a parity bit.
Which data bits are in error? We find out by adding
the bit positions of the erroneous bits.
Simply, 1 + 4 = 5. This tells us that the error is in bit
5. If we change bit 5 to a 1, all parity bits check and
our data is restored.
Conclusion (1 of 2)

Computers store data in the form of bits,


bytes, and words using the binary numbering
system.
Hexadecimal numbers are formed using four-
bit groups called nibbles.

magnitude representation.
Floating-point numbers are usually coded
using the IEEE 754 floating-point standard.
Conclusion (2 of 2)

Floating-point operations are not necessarily


associative or distributive.
Character data is stored using ASCII, EBCDIC,
or Unicode.
Error detecting and correcting codes are
necessary because we can expect no
transmission or storage medium to be perfect.
CRC, Reed-Solomon, and Hamming codes are
three important error control codes.

You might also like