Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI206 - Computer Organization & Programming

Similar presentations


Presentation on theme: "CSCI206 - Computer Organization & Programming"— Presentation transcript:

1 CSCI206 - Computer Organization & Programming
Introduction to Floating Point Numbers zyBook: 10.5

2 Real Numbers in Binary Recall the equation describing a positional number system:

3 Real Numbers in Binary Recall the equation describing a positional number system: This can be extended to real numbers: decimal point!

4 Examples base 10 0.1 in binary is = 0.5 (base 10)

5 Real Numbers in Binary Fractions of a power of 2 are easy
Other values are represented using the sum of fractions with a power of 2 denominator

6 Real Numbers in Binary For example, 0.510 = 0.12
= = 0.112 = = = =

7 Algorithm to Convert Decimal to Binary
For decimal to binary integers we divided by 2 and record the remainder. For decimal to binary fraction numbers we multiply by 2 and record the integer part. Example: convert to binary.

8 binary digits beginning to the right of the decimal
to binary binary digits beginning to the right of the decimal

9 binary digits beginning to the right of the decimal
to binary binary digits beginning to the right of the decimal

10 binary digits beginning to the right of the decimal
to binary binary digits beginning to the right of the decimal

11 binary digits beginning to the right of the decimal
to binary binary digits beginning to the right of the decimal

12 binary digits beginning to the right of the decimal
to binary binary digits beginning to the right of the decimal only work with fractional part!

13 fraction part is zero, stop!
to binary = It appears magic, but the reason behind the algorithm is to find k, such that v * 2^k = 1.0, as v is expressed as b0*2^(-1)+b1*2^(-2) … fraction part is zero, stop!

14 Convert binary to decimal
Convert to decimal == == 1/16 + 1/32 == 3/32 ==

15 Number Representation in Computing
For a given range of integers, there is a corresponding range of (exact) binary representations Example: the range [0-15] corresponds to the 4-bit binary numbers 0000 through 1111.

16 Number Representation in Computing
Within a range of real numbers, there is no way to encode all possible values. Example: the range [ ] has an infinite number of points, so we would need an infinite number of bits to represent all of the possible values! As a result, in computing, real numbers are approximate. Activity 24, question 1 - 2

17 An Observation Many common base 10 real numbers generate an infinite number of binary digits

18 Fixed vs. Floating Point Approximations

19 Floating Point Representation
Decimal notation Scientific notation 2 2×100 300 3×102 321.7 3.217×102 −53,000 −5.3×104 6,720,000,000 6.72×109 0.2 2×10−1 Floating Point Representation Where S is the sign bit M is a fixed point number (precision of numbers) E is a signed integer (range of numbers) S Exponent Mantissa or Fraction 32 or 64 bit word

20 IEEE 754 Standard (1985) S Exponent Mantissa One bit for Sign
Single precision float (32 bits) 8 bit Exponent 23 bit Mantissa Double precision float (64 bits) 11 bit Exponent 52 bit Mantissa

21 IEEE 754 Standard (1985) S Exponent Mantissa
Mantissa is normalized, meaning it is a fixed point number in the form 1.xxxxxx to save one bit, the 1. is implicit (not represented) Exponent is represented in biased form B = 127 for single B = 1023 for double


Download ppt "CSCI206 - Computer Organization & Programming"

Similar presentations


Ads by Google