Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lesson Objectives Aims You should know about: Binary numbers ‘n’ that.

Similar presentations


Presentation on theme: "Lesson Objectives Aims You should know about: Binary numbers ‘n’ that."— Presentation transcript:

1 Lesson Objectives Aims You should know about: Binary numbers ‘n’ that.

2 Lesson Objectives Aims Key Words
Be able to represent and normalise floating point numbers in binary Be able to perform floating point arithmetic including positive and negative numbers Key Words

3 For this lesson to work…
You must understand 2’s compliment If you don’t go back and look at it. A quick recap: If a number starts with 0, it’s positive, do nothing with it. If it starts with a 1, it’s negative, flip the bits and add 1 to discover the real number

4 Floating point At present, we have looked only at integer number representation Which means that numbers like 3.25 give us a headache Hence why we need… …a point.

5 Bit allocation In any computer, there is a byte/word length that the processor works with: 8 16 32 64 This means within that constraint, we must decide how many bits to allocate to: the Mantissa (the number) and… the Exponent (the number of places we shift the decimal point)

6 Denary floating point 1.4521 x 103 1.4521 x 10-3
If the exponent is POSITIVE then we move the decimal place to the RIGHT to get the original number 1452.1 If the exponent is NEGATIVE then we move the decimal place to the LEFT and fill the empty places with zeroes

7 Positive numbers we understand:
Let’s try Let’s try 9.25 in binary. Positive numbers we understand: Easy. What about the decimal places? 128 64 32 16 8 4 2 1

8 So after the decimal point, we continue to divide the place value by 2
This has some points of interest: How many bits do we use for the integer and fractional part? The accuracy of the fractional part is dictated by the number of bits assigned… So clearly a FIXED point is incredibly inflexible in a fixed bit width 8 4 2 1 . 1/8 1/16

9 Hence… …The need for a floating point. This way we can represent numbers with greater accuracy than with a fixed point. Hence the need for an exponent The concept of representing fractional amounts remains the same.

10 So, how do we get the exponent?
Simply take our number and shift the point left until it reaches the first number: Number of shifts – 3. Assume 4 bit exponent – 0011 Final number: 8 4 2 1 . 1/8 1/16

11 Number of shifts – 3. Assume 4 bit exponent – 0011
Final number: To avoid this being negative, we actually need one final shift: (this is normalisation…)

12 Negative numbers Convert as a positive Then two’s compliment the mantissa ONLY -9.25

13 Overflow and underflow
Overflow and underflow will cause one or more of the following: A flag to be raised in the status register An interrupt to occur Program instability/crash Unpredictable behaviour

14 Truncation When a number is recurring it may be truncated – i.e. cut off E.g becomes 3.33 Rounding When a number is too large to be stored it may be rounded This will cause loss of precision It does NOT raise an exception/flag/interrupt

15 Normalisation With any number >=1 you will automatically normalise it during conversion However, following our method to the letter, with smaller numbers you may end up with leading zeroes Which is a waste of time (and more importantly precision)

16 A normalised number A normalised number will always start with a one AFTER the sign! (this is the potentially confusing bit) SIGN Point MUST be a one Fractional Part Exponent . 1

17 Notice the exponent decreases by 1 for each shift.
Not normalised, but still a float: (5 bit mantissa, 3 bit exponent) The same number normalised: Notice the exponent decreases by 1 for each shift. Why do this? Much less chance of truncation Better precision

18 Addition 4 bit mantissa, 4 bit exponent First, match the second exponent to the first:

19 To match this we go from 3 (0011) to 2 (0010). If we reduce the number, the mantissa now SHIFTS LEFT by that amount: 0100 now becomes Our calculation is now: =

20 = Now normalise, because this number is currently negative: 0111 – mantissa has moved right so add one to the exponent:

21 Another Example Step 1 - Align the exponents Remembering if exponent increases then you move the mantissa bits RIGHT and if the exponent decreases then move the mantissa bits LEFT

22 – this exponent needs to match the others Which gives:

23 Step 2 – Perform the addition:
1111 – carry bits, note the overflow This number in denary = 0.25

24 Step 3 – Normalise Mantissa becomes: 010000 Exponent? Binary 0.25 = 0.01

25 Exponent? Binary 0.25 = 0.01 Therefore in our number: Which is technically the binary point needs to move LEFT one place. A move left is a NEGATIVE shift!!

26 Therefore: Exponent = 1 shift = 0001 binary However it is a NEGATIVE shift so 2’s compliment: 0001 1110 Add one 1111

27 So…

28 Subtraction As addition: Match the exponents SHIFT the mantissa as necessary Two’s compliment the second mantissa Add Normalise

29 Review/Success Criteria
You should know: That this is entirely unnecessary…


Download ppt "Lesson Objectives Aims You should know about: Binary numbers ‘n’ that."

Similar presentations


Ads by Google