Sie sind auf Seite 1von 34

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

CS 21 - Computer Organization and Assembly Language Programming


IEEE 754 Standard: Representing Floating Point Numbers

University of the Philippines - Diliman College of Engineering Department of Computer Science

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Outline

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Outline

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Whole numbers vs Real Numbers

Whole Numbers no fractional part may refer to


Positive natural numbers: 1, 2, 3, ... Non-negative natural numbers: 0, 1, 2, 3, ... Integer: ..., -3, -2, -1, 0, 1, 2, 3, ...

Real Numbers used to represent continuous quantities composed of


rational irrational

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Why do we need to represent real numbers?

Even practical stu are continuous in nature. Many scientic computation results are real numbers integers simply inadequate!

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Radix Point

key element in representing real numbers divides whole from partial


whole or integral to the left partial or fractional to the right

commonly known as decimal point

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Outline

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Question

Is 5.5 = 0101.0101 ?

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Decimal to Binary: Real Number


convert the INTEGRAL PART like before convert the FRACTIONAL part by
1 2 3 4

multiply fractional part by 2 integral part of the product is the binary bit remove integral part, keep fractional part repeat from step 1, until fractional part is zero, or desired accuracy is achieved

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Decimal to Binary: Real Number


convert the INTEGRAL PART like before convert the FRACTIONAL part by
1 2 3 4

multiply fractional part by 2 integral part of the product is the binary bit remove integral part, keep fractional part repeat from step 1, until fractional part is zero, or desired accuracy is achieved

Example: 0.37510 =???2 0.375 * 2 = 0.75 keep 0 0.75 * 2 = 1.5 keep 1 0.5 * 2 = 1.0 keep 1 0.37510 = 0.0112

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Decimal to Binary: Real Number

Going back to previous example: 5.5 = 5.0 and 0.5 5.010 = 1012 0.5 * 2 = 1.0 keep 1 0.510 = 0.12 5.510 = 101.12

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Binary to Decimal: Real Number

convert the INTEGRAL PART like before convert the FRACTIONAL part by multiplying to powers of 1/2 Example: convert the binary 10.101 to decimal

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Outline

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Design Issue

Where do we place the radix point? One way is to place it permanently (in the middle or anywhere we fancy). This is called the FIXED-POINT design.

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Points to ponder

Does that solution give us exibility? Are our resources ALWAYS well spent?

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Example

What is the largest integer value can it hold? What is the smallest decimal value can it hold?

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

The solution

Floating point! make the radix point oat, move it around inspired by scientic notation Example: 3.819 x 1085

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Outline

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

The Standard
Why the need for a standard? ensures interoperability between programmers, architects, engineers IEEE Standard 754 dened how oating point numbers are represented

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Components
What data do we need to represent anyway? Sign Bit Exponent Mantissa

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Component: Sign Bit

Sign bit one bit: leftmost/bit 31 1 for negative, 0 for positive

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Component: Exponent
Exponent 8 bits: bit 30 - bit 23 Raised to what? is biased
exponent is really input - 127 why the need for biasing?
It is hard to compare magnitudes of 2C numbers at a glance, the circuit required to do that is complicated. So we use unsigned numbers instead. But without biasing signed numbers could not represent negative numbers! Hence the need for biasing.

exponents that are all ALL ZEROES and ALL ONES reserved for SPECIAL numbers

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Component: Mantissa

Mantissa 23 bits: bit 22 - bit 0 Actual number in Scientic Notation, only ONE digit must be on the RIGHT of the radix point could we take advantage of binary being binary?
YES.

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Component: Mantissa

no need to represent what is on the left side of the radix point - OBVIOUS!

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Component: Mantissa

no need to represent what is on the left side of the radix point - OBVIOUS! - Its always 1

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Component: Mantissa

no need to represent what is on the left side of the radix point - OBVIOUS! - Its always 1 we get to use ALL 23 bits in representing what is on the RIGHT. In eect, we could represent 24 bits with just 23!

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Floating Point

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Example

If 81500000 is a IEEE 754 representation(in HEX) of a number, what is the number?

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Example

If 81500000 is a IEEE 754 representation(in HEX) of a number, what is the number? Convert to binary: 1000 0001 0101 0000 0000 0000 0000 0000

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Example

If 81500000 is a IEEE 754 representation(in HEX) of a number, what is the number? Convert to binary: 1000 0001 0101 0000 0000 0000 0000 0000 Group together: 1 00000010 10100000000000000000000

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Example

If 81500000 is a IEEE 754 representation(in HEX) of a number, what is the number? Convert to binary: 1000 0001 0101 0000 0000 0000 0000 0000 Group together: 1 00000010 10100000000000000000000 SIGN = 1 -> -1 EXPONENT = 00000010 -> 2, so 2 - 127 = -125 MANTISSA = 10100000000000000000000 -> 1.101

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Example

If 81500000 is a IEEE 754 representation(in HEX) of a number, what is the number? Convert to binary: 1000 0001 0101 0000 0000 0000 0000 0000 Group together: 1 00000010 10100000000000000000000 SIGN = 1 -> -1 EXPONENT = 00000010 -> 2, so 2 - 127 = -125 MANTISSA = 10100000000000000000000 -> 1.101 Answer: 1.1012 x 2125

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Example

If 81500000 is a IEEE 754 representation(in HEX) of a number, what is the number? Convert to binary: 1000 0001 0101 0000 0000 0000 0000 0000 Group together: 1 00000010 10100000000000000000000 SIGN = 1 -> -1 EXPONENT = 00000010 -> 2, so 2 - 127 = -125 MANTISSA = 10100000000000000000000 -> 1.101 Answer: 1.1012 x 2125 or 1.62510 x 2125

Real Numbers

Binary to Decimal and Vice Versa

Representation

IEEE Standard 754

Assignment

Research and study on the following: IEEE 754 double-precision Converting from non-IEEE to IEEE Why bias is 127? Do we still use 2C on IEEE 754?

Das könnte Ihnen auch gefallen