CS计算机代考程序代写 02 Computer Evolution and Performance

02 Computer Evolution and Performance

COMP228: System Hardware

Tutorial of Ch02: Data Representation

Numbers System

Example 1

Example 2

Example 3

Example 4

Example 5

Example 6

Example 7

Example 8

Taxonomy of integers numbers

Example 9

Example 10

Example 11

Example 12

Example 13

Example 14

• Two different representations for 0!

0000

0111

0011

1011

1111
1110

1101

1100

1010

1001

1000

0110

0101

0100

0010

0001

+0

+1

+2

+3

+4

+5

+6

+7-0

-1

-2

-3

-4

-5

-6

-7

Inner numbers:

Binary

representation

Seven Positive

Numbers and

“Positive” Zero

Seven Negative

Numbers and

“Negative” Zero

• Two discontinuities

Problems with Sign/Magnitude

Example 15

Example 16

Example 17

• Only one discontinuity now

0000

0111

0011

1011

1111
1110

1101

1100

1010

1001

1000

0110

0101

0100

0010

0001

+0
+1

+2

+3

+4

+5

+6

+7-8

-7

-6

-5

-4

-3

-2

-1

Inner numbers:

Binary

representation

Eight

Positive

Numbers

Re-order Negative

numbers to eliminate

one Discontinuity

Note:

Negative Numbers

still have 1 for the

most significant bit

(MSB)

• Only one zero

• One extra negative number

S/M problems solved with 2s complement

Example 18

Example 19

Example 20

Overflow Rule

Example 21

Example 22

Example 23

Valid Ranges

• For any integer data representation,

there is a LIMIT to the size of number

that can be stored.

• The limit depends upon number of bits

available for data storage.

Unsigned Integer Ranges

Range = 0 to (2n – 1)

where n is the number of bits used to store

the unsigned integer.

Numbers with values GREATER than (2n – 1)

would require more bits. If you try to store

too large a value without using more bits,

OVERFLOW will occur.

Unsigned Integer Ranges

Example: On a system that stores unsigned

integers in 16-bit words:

Range = 0 to (216 – 1)

= 0 to 65535

Therefore, you cannot store numbers larger

than 65535 in 16 bits.

Signed S/M Integer Ranges

Range = -(2(n-1) – 1) to +(2(n-1) – 1)

where n is the number of bits used to store the

sign/magnitude integer.

Numbers with values GREATER than +(2(n-1) – 1)

and values LESS than -(2(n-1) – 1) would

require more bits. If you try to store too

large/too small a value without using more bits,

OVERFLOW will occur.

S/M Integer Ranges

Example: On a system that stores unsigned

integers in 16-bit words:

Range = -(215 – 1) to +(215 – 1)

= -32767 to +32767

Therefore, you cannot store numbers larger

than 32767 or smaller than -32767 in 16 bits.

Floating Point

Example 24

Example 25

Example 26

0.1100 1000 * 0.1001 1010 = 0.0111 1000 0101 * 2^2

0.1111 0000 101 * 2^1

Example 27

IEEE-754 Floating-Point

• Floating point numbers can be stored into 32-

bits, by dividing the bits into three parts:

the sign, the exponent, and the mantissa.

1 2 9 10 32

IEEE-754 Floating-Point

• The first (leftmost) field of our floating point

representation will STILL be the sign bit:

—0 for a positive number,

—1 for a negative number.

Storing the Binary Form

How do we store a radix point?

– All we have are zeros and ones…

Make sure that the radix point is ALWAYS in

the same position within the number.

Use the IEEE 32-bit standard

→ the leftmost digit must be a 1

Solution is Normalization

Every binary number, except the one
corresponding to the number zero, can be
normalized by choosing the exponent so that the
radix point falls to the right of the leftmost 1 bit.

37.2510 = 100101.012 = 1.0010101 x 2
5

7.62510 = 111.1012 = 1.11101 x 2
2

0.312510 = 0.01012 = 1.01 x 2
-2

IEEE-754 Floating-Point

• The second field of the floating point number

will be the exponent.

• The exponent is stored as an unsigned 8-bit

number, RELATIVE to a bias of 127.

—Exponent 5 is stored as (127 + 5) or 132

–132 = 10000100

—Exponent -5 is stored as (127 + (-5)) or 122

–122 = 01111010

Example 28

How would the following exponents be

stored (8-bits, 127-biased):

2-10

28

Answers

2-10

exponent -10 8-bit

bias+127 value

117 → 01110101

28

exponent 8 8-bit

bias+127 value

135 → 10000111

Example 29

• The mantissa is the set of 0’s and 1’s to

the right of the radix point of the

normalized (when the digit to the left of the

radix point is 1) binary number.

Ex: 1.00101 X 23

(The mantissa is 00101)

▪ The mantissa is stored in a 23 bit field, so
we add zeros to the right side and store:

00101000000000000000000

Example 30

Ex 1: Find the IEEE FP representation of

40.15625

Step 1.

Compute the binary equivalent of the

whole part and the fractional part. (i.e.

convert 40 and .15625 to their binary

equivalents)

Example 30

40 .15625

– 32 Result: -.12500 Result:

8 101000 .03125 .00101

– 8 -.03125

0 .0

So: 40.15625
10

= 101000.00101
2

Decimal Floating Point to

IEEE standard Conversion

Step 2. Normalize the number by moving the

decimal point to the right of the leftmost one.

101000.00101 = 1.0100000101 x 25

Decimal Floating Point to

IEEE standard Conversion

Step 3. Convert the exponent to a biased
exponent

127 + 5 = 132

And convert biased exponent to 8-bit unsigned
binary:

132
10

= 10000100
2

Decimal Floating Point to

IEEE standard Conversion

Step 4. Store the results from steps 1-3:

Sign Exponent Mantissa

(from step 3) (from step 2)

0 10000100 01000001010000000000000

Decimal Floating Point to

IEEE standard Conversion

Ex 2: Find the IEEE FP representation of –24.75

Step 1. Compute the binary equivalent of the whole
part and the fractional part.

24 .75

– 16 Result: – .50 Result:

8 11000 .25 .11

– 8 – .25

0 .0

So: -24.75
10

= -11000.11
2

Decimal Floating Point to

IEEE standard Conversion

Step 2.

Normalize the number by moving the decimal

point to the right of the leftmost one.

-11000.11 = -1.100011 x 24

Decimal Floating Point to

IEEE standard Conversion.

Step 3. Convert the exponent to a biased
exponent

127 + 4 = 131

==> 131
10

= 10000011
2

Step 4. Store the results from steps 1-3

Sign Exponent mantissa

1 10000011 1000110..0

IEEE standard to Decimal

Floating Point Conversion.

• Do the steps in reverse order

• In reversing the normalization step move the

radix point the number of digits equal to the

exponent:

—If exponent is positive, move to the right

—If exponent is negative, move to the left

Example 31

Convert the following 32-bit binary number
to its decimal floating point equivalent:

Sign Exponent Mantissa

1 01111101 010..0

Example 31

Step 1: Extract the biased exponent and unbias

it

Biased exponent = 011111012 = 12510

Unbiased Exponent: 125 – 127 = -2

Step 2: Write Normalized number in the form:

1 . ____________ x 2 —-

For our number:

-1. 01 x 2 –2

Example 31

Mantissa
Exponent

Example 31

Step 3: Denormalize the binary number from step 2

(i.e. move the decimal and get rid of (x 2n) part):

-0.0101
2

(negative exponent – move left)

Step 4: Convert binary number to the FP equivalent
(i.e. Add all column values with 1s in them)

-0.0101
2

= – ( 0.25 + 0.0625)

= -0.312510

Example 32

Convert the following 32 bit binary number to

its decimal floating point equivalent:

Sign Exponent Mantissa

0 10000011 10011000..0

Example 32

Step 1: Extract the biased exponent and unbias

it

Biased exponent = 10000112 = 13110

Unbiased Exponent: 131 – 127 = 4

Example 32

Step 2: Write Normalized number in the form:

1 . ____________ x 2 —-

For our number:

1.10011 x 2 4

Mantissa
Exponent

Example 32

Step 4: Convert binary number to the FP equivalent

(i.e. Add all column values with 1s in them)

11001.1 = 16 + 8 + 1 +.5

= 25.510

Step 3: Denormalize the binary number from step 2
(i.e. move the decimal and get rid of (x 2n) part:

11001.1
2

(positive exponent – move right)

Binary-Coded Decimal (BCD)

Example 33

Example 33

Error Detection

Example 33

Error Detection

Example 34

Example 35

Hamming Code

Hamming Code

Hamming Code

Hamming Code

Hamming Code