Presentation is loading. Please wait.

Presentation is loading. Please wait.

Floating Point Binary Part 1

Similar presentations


Presentation on theme: "Floating Point Binary Part 1"— Presentation transcript:

1 Floating Point Binary Part 1
Data REpresentation Representing Fractional Numbers in Binary (1s and 0s) The problems of approximation Floating Point Binary Data Representation Normalisation of Floating Point Binary Numbers Representation using: Mantissa and Exponent Example Question and Answers Discussing Limitations: Range and Precision

2 Let’s start with two questions:
Why does this happen? Note the 4 at the end! How can we use Binary to represent Fractional/decimal numbers We know how to represent positive and negative numbers in Binary, but what about fractions? = 011 = 100 2.5? = ??? ? ? ?

3 Representing Decimal Fractions:
2.5 128 64 32 16 8 4 2 1 1/8 1 1

4 Representing Decimal Fractions:
12.75 128 64 32 16 8 4 2 1 1/8 1 1 1 1

5 Representing Decimal Fractions:
Another way of looking at it: Decimal fraction: 0.125 has value 1/10 + 2/ /1000, Binary Fraction: 0.001 has value 0/2 + 0/4 + 1/8

6 What about a no. that isn’t a multiple of 2?
1/3? 3.3 ??!? 128 64 32 16 8 4 2 1 1/8 1 1 1

7 Unfortunately, most decimal fractions cannot be represented exactly as binary fractions.

8 And what are the consequences of this?
A consequence is that, in general, the decimal floating-point numbers you enter are only an approximation of the binary floating-point numbers actually stored in the machine. ?

9 Consider the nature of approximation
The problem is easier to understand, at first, in base 10. Consider the fraction 1/3. You can approximate that as a base 10 fraction: 0.3 or, better, 0.33 0.333

10 Floating Point Binary Approximation
In the same way, no matter how many base 2 digits you’re willing to use, the decimal value 0.1 cannot be represented exactly as a base 2 fraction. In base 2, 1/10 is the infinitely repeating fraction Stop at any finite number of bits, and you get an approximation. = 1 ?

11 Precision available in Python
On a typical machine running Python, there are 53 bits of precision available for a Python float, so the value stored internally when you enter the decimal number 0.1 is the binary fraction which is close to, but not exactly equal to, 1/10.

12 Precision available in Python
Another consequence is that since 0.1 is not exactly 1/10, summing ten values of 0.1 may not yield exactly 1.0, either ….

13 Now, let’s consider HUGE numbers
Ever wondered how a computer might be able to store a number that is GREAT in MAGNITUDE? What’s the biggest number you can think of?

14 How do we go about representing these?
The Distance from Venus to the Sun is 6,700,000 miles Number of blood cells in an adult is an even bigger number: 25,000,000,000,000

15 You may recall ‘Scientific Notation’
Scientific Notation is often used with very large decimal numbers. It makes them more manageable to deal with (and represent!)

16 We call it: Floating Point Binary Representation
A similar thing is done in Binary form We call it: Floating Point Binary Representation Note: It is called the FLOATING POINT METHOD because the location of the “point” moves around. (This, as you will see, allows for greater efficiency in representation) Example: An 8 Bit Floating Point Number *Floating Point Notation is basically SCIENTIFIC NOTATION IN BASE 2 Mantissa Exponent 1 *Floating Point Notation is basically SCIENTIFIC NOTATION IN BASE 2

17 The Mantissa is a negative number
The floating point number below is in twos complement format Mantissa Exponent 1 The Exponent part indicates where the “point” needs to be The Mantissa is a negative number *You may want to review Twos complement (see presentation: ‘Mastering Twos Complement’)

18 Because the Exponent is + 2, the Mantissa becomes 100.1
8 bit floating point number: Analysis Mantissa Exponent 1 The Exponent is + 2 Because the Exponent is + 2, the Mantissa becomes 100.1 *You may want to review Twos complement (see presentation: ‘Mastering Twos Complement’)

19 8 bit floating point number: Analysis
Mantissa Exponent 1 Mantissa: As this is in twos complement and negative: flip the bits, to the left of the last 1

20 8 bit floating point number: Analysis
Mantissa Exponent 1 Step 1: becomes Step 2: Flip bits: Step 3: = 3.5 Step 4: Because we know it is a negative number it is -3.5

21 Question: What is this 8 bit floating point number in Decimal?
Answer Step 1: Find value of Exponent = 2 Step 2: becomes Step 3: Flip bits: Step 4: = 3.5 Step 5: It’s a negative number so it’s - 3.5

22 Key words (while referring to a number)
Precision/Accuracy Magnitude/Range/Size The greater the allocation to the Mantissa – the greater the precision 1 The greater the allocation to the Exponent– the greater the range of the number 1

23 Another practice Question
Answer Break the number into 2 parts. Place a “point” between the MSB and the next one. 1. Question used from OCR A Level past paper with permission. 11.0 = +3 in Decimal Figure out the value of the exponent. Also, note the SIGN of both the Mantissa and Exponent The exponent is + 2 01100 becomes 11.00 Move the “point” the required places to the right or the left (in this case, right)

24 Limitations of Floating Point
Fill in the Blanks Limitations of Floating Point Floating Point is always contained in a Fixed amount of Bits. One example is that a 32 bit computer can use 4 bytes to represent a Floating Point number (i.e 32 bits) This means there is a limit as to the range of numbers or the precision of numbers that can be represented. F x R P

25 Why was Floating Point developed?
It can cover a wide range and yet have reasonable precision It can do so because the precision is allowed to float compared to a fixed point scheme. W P F F

26 A discussion on the need for FPBinary
Consider an engineer designing a highway Computer memory is limited, so you cannot store numbers with infinite precision – at some point you would have to cut off. But how much accuracy is needed? How many integer digits and how many fraction digits would you need – and why? L P ….and the design of a microchip

27 Accuracy vs range …. To an engineer building a highway, extreme precision is not necessary – whether it’s 10 meters or meters wide is not going to make a HUGE difference. His measurements are probably not that accurate. But to someone designing a microchip, meters (a tenth of a millimetre) is significant – again, in this case he would never have to deal with a distance larger than 0.1 meters. RANGE ACCURACY

28 How to satisfy the chip builder and highway designer?
a number format has to provide accuracy for numbers at very different magnitudes. However, only relative accuracy is needed Also it is important that having a fixed number of integer and fractional digits is not useful - and the solution is a format with a floating point.

29 Two advantages for floating point numbers
Speed Efficiency Can deal with huge numbers (like the size of the universe) Can deal with relatively precise numbers (like ) Image Source: Wikipedia:

30 Further research on this topic
rg/wiki/Floating_point g/home/ehchua/prog ramming/java/DataR epresentation.html 1IfStY0


Download ppt "Floating Point Binary Part 1"

Similar presentations


Ads by Google