Presentation is loading. Please wait.

Presentation is loading. Please wait.

Floating Point Numbers

Similar presentations


Presentation on theme: "Floating Point Numbers"— Presentation transcript:

1 Floating Point Numbers
CS208

2 Floating Point Numbers
Now you've seen unsigned and signed integers. In real life we also need to be able represent numbers with fractional parts (like: & 45.39). Called Floating Point numbers. You will learn the IEEE 32-bit floating point representation.

3 Floating Point Numbers
In the decimal system, a decimal point (radix point) separates the whole numbers from the fractional part Examples: 37.25 ( whole = 37, fraction = 25/100)

4 Floating Point Numbers
For example, can be analyzed as: Tens Units Tenths Hundredths 37.25 = (3 x 10) + (7 x 1) + (2 x 1/10) + (5 x 1/100)

5 Binary Equivalence The binary equivalent of a floating point number can be determined by computing the binary representation for each part separately. 1) For the whole part: Use subtraction or division method previously learned. 2) For the fractional part: Use the subtraction or multiplication method (to be shown next)

6 Fractional Part – Multiplication Method
In the binary representation of a floating point number the column values will be as follows: … … … /2 1/4 1/ /16… … …

7 Fractional Part – Multiplication Method
Ex 1. Find the binary equivalent of 0.25 Step 1: Multiply the fraction by 2 until the fractional part becomes x 2 0.5 1.0 Step 2: Collect the whole parts in forward order. Put them after the radix point

8 Fractional Part – Multiplication Method
Ex 2. Find the binary equivalent of 0.625 Step 1: Multiply the fraction by 2 until the fractional part becomes x 2 1.25 0.50 1.0 Step 2: Collect the whole parts in forward order. Put them after the radix point

9 Fractional Part – Subtraction Method
Start with the column values again, as follows: … … … /2 1/4 1/8 1/ / /64… … …

10 Fractional Part – Subtraction Method
Starting with 0.5, subtract the column values from left to right. Insert a 0 in the column if the value cannot be subtracted or 1 if it can be. Continue until the fraction becomes .0 Ex 1. .0

11 Binary Equivalent of FP number
Ex 2. Convert 37.25, using subtraction method.   37 - 4 1 -1 .25 - .25 .0 =

12 Binary Equivalent of FP number
Ex 3. Convert , using subtraction method.   =

13 Try It Yourself Convert the following decimal numbers to binary: (Answers on next page)

14 Answers = =

15 Problem storing binary form
We have no way to store the radix point! Standards committee came up with a way to store floating point numbers (that have a decimal point)

16 IEEE Floating Point Representation
Floating point numbers can be stored into 32-bits, by dividing the bits into three parts: the sign, the exponent, and the mantissa. 1

17 IEEE Floating Point Representation
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.

18 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

19 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. = = x 25 = = x 22 = = 1.01 x 2-2

20 IEEE Floating Point Representation
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 ( ) or 132 132 = Exponent -5 is stored as (127 + (-5)) or 122 122 =

21 Try It Yourself How would the following exponents be stored (8-bits, 127-biased): 2-10 28 (Answers on next slide)

22 Answers 2-10 exponent -10 8-bit bias +127 value 117  01110101 28
117  28 exponent bit 135 

23 IEEE Floating Point Representation
The mantissa is the set of 0’s and 1’s to the left of the radix point of the normalized (when the digit to the left of the radix point is 1) binary number. Ex: 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:

24 Decimal Floating Point to IEEE standard Conversion
 Ex 1: Find the IEEE FP representation of Step 1. Compute the binary equivalent of the whole part and the fractional part. (i.e. convert 40 and to their binary equivalents)

25 Decimal Floating Point to IEEE standard Conversion
  Result: Result: So: =

26 Decimal Floating Point to IEEE standard Conversion
Step 2. Normalize the number by moving the decimal point to the right of the leftmost one. = x 25

27 Decimal Floating Point to IEEE standard Conversion
Step 3. Convert the exponent to a biased exponent = 132 And convert biased exponent to 8-bit unsigned binary: 13210 =

28 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)

29 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.  Result: Result:   So: =

30 Decimal Floating Point to IEEE standard Conversion
  Step 2. Normalize the number by moving the decimal point to the right of the leftmost one. = x 24

31 Decimal Floating Point to IEEE standard Conversion.
Step 3. Convert the exponent to a biased exponent = 131 ==> = Step 4. Store the results from steps 1-3 Sign Exponent mantissa

32 Try It Yourself Convert the following numbers to IEEE floating point representation:

33 Answers = =

34 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

35 IEEE standard to Decimal Floating Point Conversion.
Ex 1:  Convert the following 32-bit binary number to its decimal floating point equivalent: Sign Exponent Mantissa

36 IEEE standard to Decimal Floating Point Conversion..
Step 1: Extract the biased exponent and unbias it Biased exponent = = Unbiased Exponent: 125 – 127 = -2

37 IEEE standard to Decimal Floating Point Conversion..
Step 2: Write Normalized number in the form: 1 . ____________ x For our number: x 2 –2 Exponent Mantissa

38 IEEE standard to Decimal Floating Point Conversion.
Step 3: Denormalize the binary number from step 2 (i.e. move the decimal and get rid of (x 2n) part): (negative exponent – move left) Step 4: Convert binary number to the FP equivalent (i.e. Add all column values with 1s in them) = - ( ) =

39 IEEE standard to Decimal Floating Point Conversion.
Ex 2: Convert the following 32 bit binary number to its decimal floating point equivalent: Sign Exponent Mantissa

40 IEEE standard to Decimal Floating Point Conversion..
Step 1: Extract the biased exponent and unbias it Biased exponent = = Unbiased Exponent: 131 – 127 = 4

41 IEEE standard to Decimal Floating Point Conversion..
Step 2: Write Normalized number in the form: 1 . ____________ x For our number: x 2 4 Exponent Mantissa

42 IEEE standard to Decimal Floating Point Conversion.
Step 3: Denormalize the binary number from step 2 (i.e. move the decimal and get rid of (x 2n) part: (positive exponent – move right) Step 4: Convert binary number to the FP equivalent (i.e. Add all column values with 1s in them) = =

43 Try It Yourself Convert the following IEEE floating point numbers to decimal:

44 Answers = = =


Download ppt "Floating Point Numbers"

Similar presentations


Ads by Google