Factional Values What is 0.75 in binary? How could we represent fractions? • In decimal: – As fractions : 1/5 How could we represent fractions? • In decimal: – As fractions : 1/5 – As decimals : 0.2 hundreds 102 tens 101 ones 100 tenths 10-1 hundredths 10-2 0 2 0 Column Pattern • What goes to the right of 1’s column? 23 8 22 4 21 2 20 1 Column Pattern • Negative powers of two: 23 8 -3 2 22 4 = 1 23 21 2 = 20 1 1 8 2-1 0.5 = 0.125 2-2 0.25 2-3 0.125 2-4 0.0625 Number • Binary decimal: 23 8 22 4 21 2 20 1 2-1 0.5 2-2 0.25 1 0 1 1 2-3 0.125 2-4 0.0625 10.112 = 2 + 0.5 + 0.25 = 2.7510 Number • Binary decimal: 23 8 22 4 21 2 20 1 2-1 0.5 2-2 0.25 2-3 0.125 2-4 0.0625 0 1 0 0 1 0.10012 = 0.5 + 0.0625 = 0.562510 Number • Binary decimal: 23 8 22 4 21 2 20 1 2-1 0.5 2-2 0.25 2-3 0.125 2-4 0.0625 0 1 0 1 0 0.10102 = 0.5 + 0.125 = 0.62510 Missing Numbers • Where is 0.6? 0.10012 = 0.5 + 0.0625 = 0.562510 0.10102 = 0.5 + 0.125 = 0.62510 More Digits • An attempt with 11 decimal digits: Binary Decimal Place 2-1 2-2 2-3 2-4 2-5 2-6 2-7 2-8 2-9 2-10 2-11 Bit 1 0 0 1 1 0 0 1 1 0 1 Value 0.5 0 0 0.0625 0.03125 0 0 0 0.000488 Total • Can only approximate 0.600098 0.003906 0.001953 Decimals are an Approximation • Decimal has same issue: – What is 1/3 ?? – What is 2/7 ?? More Digits • Given limited digits, must allocate them – To left of decimal: Bigger values 25 32 24 16 23 8 22 4 21 2 20 1 2-1 0.5 2-2 0.25 – To right of decimal: More accurate values 21 2 20 1 2-1 0.5 2-2 0.25 2-3 0.125 2-4 0.0625 2-5 0.03125 2-6 0.015625 Fixed Decimal Problems • Fixed decimal points waste space: 400,000,000,000,000,000 0.000000000000025 Fixed Decimal Problems • Fixed decimal points waste space: 400,000,000,000,000,000 vs 4.0 x 1017 0.000000000000025 vs 2.5 x 10-14 • In computers, space is precious – Computers use a floating decimal point (Like scientific notation) Floating Point Sign 0 Exponent 1 0 Mantissa 0 1 0 • Bits used to represent 3 parts: – Sign – Exponent – Fraction (or Mantissa) 0 0 Sign Sign 0 Exponent 1 0 Mantissa 0 1 • 0 = positive, 1 = negative 0 0 0 Exponent Sign 0 Exponent 1 0 Mantissa 0 1 0 0 0 • Binary integer in excess notation – Gives power of 2 to multiply by 100 = 0 So 20 Binary 000 001 010 011 100 101 110 111 Value -4 -3 -2 -1 0 1 2 3 Mantissa Sign 0 Exponent 1 0 Mantissa 0 1 0 0 0 • Fractional Value – Always a decimal 1000 = 0.5 2-1 0.5 2-2 0.25 2-3 0.125 2-4 0.0625 1 0 0 0 Examples Sign Exponent 0 + 1 0 0 0 so 20 + 20 x 0.5 = + 1 x 0.5 = + 0.5 2-1 0.5 2-2 0.25 2-3 0.125 2-4 0.0625 1 0 0 0 Mantissa 1 0 0 0.5 0 Examples Sign Exponent 1 - 1 1 1 3 so 23 - 23 x 0.5625 = = - 8 x 0.5625 -4.5 2-1 0.5 2-2 0.25 2-3 0.125 2-4 0.0625 1 0 0 1 Mantissa 1 0 0 0.5625 1 Examples Sign 0 + + 2-4 2-1 0.5 2-2 0.25 2-3 0.125 2-4 0.0625 0 1 0 0 Exponent 0 0 -4 so 2-4 x 0.25 = + 0.0625 x 0.25 = +0.015625 Mantissa 0 or 1 24 0 1 0 0.25 0 Floating Point Math is HARD Sign 0 Exponent 1 0 Mantissa 0 1 0 0 • XOR the signs • Calculate new exponent – Excess Notation – different math rules! • Calculate new mantissa – Normal binary multiplication 0 Choices, choices • Choices – More bits to exponent – More bits to mantissa – How we represent each • What is our excess start point? • Do mantissas have to start with 1? 32 Bit Floating Point • PC processors are 32 or 64 bit – Size of data they can work on at one time • IEEE specifies conventions for floating points: Remember… • Decimals are approximate • 32 bit float gives 6-7 significant decimal digits • 64 bit float gives 15-16 significant decimal digits