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
First Semester, Academic Year 2011 - 2012
Real Numbers
Binary to Decimal and Vice Versa
Outline
1
Real Numbers
2
Binary to Decimal and Vice Versa
3
Representation
4
IEEE Standard 754
Representation
IEEE Standard 754
Real Numbers
Binary to Decimal and Vice Versa
Outline
1
Real Numbers
2
Binary to Decimal and Vice Versa
3
Representation
4
IEEE Standard 754
Representation
IEEE Standard 754
Real Numbers
Binary to Decimal and Vice Versa
Representation
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
IEEE Standard 754
Real Numbers
Binary to Decimal and Vice Versa
Representation
Why do we need to represent real numbers?
Even practical stuff are continuous in nature. Many scientific computation results are real numbers integers simply inadequate!
IEEE Standard 754
Real Numbers
Binary to Decimal and Vice Versa
Representation
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”
IEEE Standard 754
Real Numbers
Binary to Decimal and Vice Versa
Outline
1
Real Numbers
2
Binary to Decimal and Vice Versa
3
Representation
4
IEEE Standard 754
Representation
IEEE Standard 754
Real Numbers
Binary to Decimal and Vice Versa
Representation
Question
Is 5.5 = 0101.0101 ?
IEEE Standard 754
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.625 * 2 = 1.25 keep 1 0.25 * 2 = 0.5 keep 0 0.5 * 2 = 1.0 keep 1
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
Outline
1
Real Numbers
2
Binary to Decimal and Vice Versa
3
Representation
4
IEEE Standard 754
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? we could 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
Points to ponder
Does that solution give us flexibility? Are our resources ALWAYS well spent?
IEEE Standard 754
Real Numbers
Binary to Decimal and Vice Versa
Representation
Example
What is the largest integer value can it hold? What is the smallest decimal value can it hold?
IEEE Standard 754
Real Numbers
Binary to Decimal and Vice Versa
Representation
The solution
Floating point! make the radix point �float�, move it around inspired by scientific notation Example: 3.819 x 1085
IEEE Standard 754
Real Numbers
Binary to Decimal and Vice Versa
Outline
1
Real Numbers
2
Binary to Decimal and Vice Versa
3
Representation
4
IEEE Standard 754
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 defined how floating point numbers are represented
Real Numbers
Binary to Decimal and Vice Versa
Representation
Components What data do we need to represent anyway? Sign Bit Exponent Mantissa
IEEE Standard 754
Real Numbers
Binary to Decimal and Vice Versa
Component: Sign Bit
Sign bit one bit: leftmost/bit 31 1 for negative, 0 for positive
Representation
IEEE Standard 754
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 Scientific 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! we get to use ALL 23 bits in representing what is on the RIGHT. In effect, we could represent 24 bits with just 23!
Real Numbers
Binary to Decimal and Vice Versa
Floating Point
Representation
IEEE Standard 754
Real Numbers
Binary to Decimal and Vice Versa
Representation
IEEE Standard 754
Example
If 01500000 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 01500000 is a IEEE 754 representation(in HEX) of a number, what is the number? 0000 0001 0101 0000 0000 0000 0000 0000
Real Numbers
Binary to Decimal and Vice Versa
Representation
IEEE Standard 754
Example
If 01500000 is a IEEE 754 representation(in HEX) of a number, what is the number? 0000 0001 0101 0000 0000 0000 0000 0000 SIGN = 0 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 01500000 is a IEEE 754 representation(in HEX) of a number, what is the number? 0000 0001 0101 0000 0000 0000 0000 0000 SIGN = 0 EXPONENT = 00000010 = 2, so 2 - 127 = -125 MANTISSA = 10100000000000000000000 = 1.101 Answer: 1.101 x 2−125