1 / 18

Fractions in Binary

Fractions in Binary. Fractions. Binary doesn’t just do integers (whole numbers) it can also be used for fractions though it isn’t as accurate as decimals in denary e.g. 136.75 could be expressed as 136 + 1/2 + 1/4 128 64 32 16 8 4 2 1 . 1/2 1/4 1/8 1/16

youngr
Download Presentation

Fractions in Binary

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Fractions in Binary

  2. Fractions • Binary doesn’t just do integers (whole numbers) it can also be used for fractions though it isn’t as accurate as decimals in denary e.g. 136.75 could be expressed as 136 + 1/2 + 1/4 128 64 32 16 8 4 2 1 . 1/2 1/4 1/8 1/16 1 0 0 0 1 0 0 0 . 1 1 0 0 This is binary notation – the decimal point is in a fixed point

  3. The problem • Clearly with a limited number of places after the decimal point it is far less accurate as only a limited range of decimals can be displayed • The number of extra places after the decimal point increase accuracy

  4. Fixed point example • 1 byte = 8 bits If 4 bits were assigned after the decimal Place (this does not take up any bits) 8 4 2 1 . 1/2 1/4 1/8 1/16 0 1 1 1 0 1 0 1

  5. Task • Look at the table on page 195 showing binary fractions • Do questions 1-3 on page 196

  6. So how do you represent all of the other decimals in binary? • Floating point binary

  7. Floating Point Binary • In decimal, you can use scientific notation for really big numbers • e.g. 1,2,0000,0000,0000 Would be 0.12 x 10 13 Exponent Which defines where to place the decimal point In this case move 13 places to the right Mantissa Which holds the digits

  8. Floating Point Binary • In binary, firstly bits are shared between the mantissa and the exponent • In the example below, 2 bytes (16 bits) with 10 bits for the mantissa and 6 for the exponent Mantissa Exponent 0110100000 000011 = 0.1101 x 2 Sign bit 3 This is a sign bit – if positive i.e. 0 move the decimal point right, if negative i.e. 1 move the decimal point left There is always an imaginary decimal here

  9. Floating Point Binary Mantissa Exponent 0110100000 000011 = 0.1101 x 2 = 110.1 = 6.5 in denary 3

  10. Task • Do Q4 on page196 Rules: • Place the point between the sign bit and the first digit of the mantissa • Convert the exponent to its decimal form (positive or negative) • Move the point right if the exponent is positive or left if negative • Convert the resulting binary number to denary

  11. If the mantissa is negative Mantissa Exponent 1110100000 000011 1.1101 would become 1110.1 -8 4 2 1 . ½ 1 1 1 0 . 1 = -8+4+2+0.5 = -1.5 Negative sign bit Move three places right Negative leftmost bit

  12. What if the mantissa and exponent are negative? Mantissa Exponent 1100000000 111110 1.1 -2 Move the point left and fill with 1’s as you do so: 1.111 -1+0.5+0.25+0.125 = -0.125

  13. Task • Do question 5 on page 197

  14. Normalisation • In order to get the most accurate representation possible with a given size of mantissa, no zeros should be put to the left of the most significant bit (not including the sign bit) • E.g. in decimal: 0.034568x10 would be normalised to 0.34568x10 A binary number in normalised form will have the first bit of the mantissa not including the sign bit as a 1 9 8

  15. To normalise a number in binary 0 000110101 000010 • put in the binary point and convert the exponent to decimal: 0.000110101 Exponent 2 • Move the number to the correct position and count the number of movements to the left to get the binary point before the first 1 0.110101000 required 3 left places • Take 3 away from the exponent of 2: 2-3 = -1 • Convert -1 back to binary 0 110101000 11111

  16. To normalise a negative number in binary • With a negative number, the most significant bit not including the sign bit will be a 0 • Shift the number left until the first bit (not the sign bit) is a zero then adjust the exponent

  17. To normalise a negative number in binary 1 111100100 000011 • put in the binary point and convert the exponent to decimal: 1.111100100 Exponent 3 • Move the number to the correct position and count the number of movements to the left to get the binary point before the first 0 1.001000000 required 4 left places • Take 4 away from the exponent of 3: 4-3 = -1 • Convert -1 back to binary 1.001000000 11111

  18. Task • Do question 6 and 7 on page 198 • Read the hint on page 198 • Do exercises on page 199

More Related