**Unformatted text preview:**

Lecture 5 Floating Point Arithmetic AMath 352 Wed Apr 7 1 15 Binary Representation and Base 2 Arithmetic Most computers today use binary or base 2 arithmetic This is natural since on o gates can represent a 1 on or a 0 o and these are the only two digits in base 2 In base 10 a natural number is represented by a sequence of digits from 0 to 9 with the right most digit representing 1 s or 100 s the next representing 10 s or 101 s the next representing 100 s or 102 s etc In base 2 the digits are 0 and 1 and the right most digit represents 1 s or 20 s the next represents 2 s or 21 s the next 4 s or 22 s etc 2 15 Then subtract 24 from 27 to nd that the remainder is 11 Since 23 is less than 11 a 1 goes in the next position to the right 11 Subtracting 23 from 11 leaves 3 which is less than 22 so a 0 goes in the next position 110 Since 21 is less than 3 a 1 goes in the next position and since 3 21 1 another 1 goes in the right most position to give 27 110112 Binary Representation of Natural Numbers Consider the decimal number 27 To nd its binary representation rst nd the highest power of 2 that is less than or equal to 27 this is 24 so a 1 goes in the fth position from the right of the number 1 3 15 Subtracting 23 from 11 leaves 3 which is less than 22 so a 0 goes in the next position 110 Since 21 is less than 3 a 1 goes in the next position and since 3 21 1 another 1 goes in the right most position to give 27 110112 Binary Representation of Natural Numbers Consider the decimal number 27 To nd its binary representation rst nd the highest power of 2 that is less than or equal to 27 this is 24 so a 1 goes in the fth position from the right of the number 1 Then subtract 24 from 27 to nd that the remainder is 11 Since 23 is less than 11 a 1 goes in the next position to the right 11 3 15 Binary Representation of Natural Numbers Consider the decimal number 27 To nd its binary representation rst nd the highest power of 2 that is less than or equal to 27 this is 24 so a 1 goes in the fth position from the right of the number 1 Then subtract 24 from 27 to nd that the remainder is 11 Since 23 is less than 11 a 1 goes in the next position to the right 11 Subtracting 23 from 11 leaves 3 which is less than 22 so a 0 goes in the next position 110 Since 21 is less than 3 a 1 goes in the next position and since 3 21 1 another 1 goes in the right most position to give 27 110112 3 15 Binary Arithmetic with Natural Numbers Binary arithmetic is carried out in a similar way to decimal arithmetic except that when adding binary numbers one must remember that 1 1 is 102 To add the two numbers 10 10102 and 27 110112 we align their binary digits and do the addition as below 0 0 1 1 1 1 0 1 1 1 1 0 1 0 0 You can check that 1001012 is equal to 37 Subtraction is similar with borrowing from the next column being necessary when subtracting 1 from 0 Multiplication and division follow similar patterns 4 15 Not all rational numbers can be represented with nite decimal expansions The number 1 3 for example is 333 with the bar over the 3 meaning that this digit is repeated in nitely many times The same is true for binary expansions although the numbers that require an in nite binary expansion may be di erent from the ones that require an in nite decimal expansion Rational Numbers in Base 2 Just as we represent rational numbers using decimal expansions we can also represent them using binary expansions The digits to the right of the decimal point in base 10 represent 10 1 s tenths 10 2 s hundredths etc while those to the right of the binary point in base 2 represent 2 1 s halves 2 2 s fourths etc For example the fraction 11 2 is 5 5 in base 10 while it is 101 12 in base 2 one 22 one 20 and one 2 1 5 15 Rational Numbers in Base 2 Just as we represent rational numbers using decimal expansions we can also represent them using binary expansions The digits to the right of the decimal point in base 10 represent 10 1 s tenths 10 2 s hundredths etc while those to the right of the binary point in base 2 represent 2 1 s halves 2 2 s fourths etc For example the fraction 11 2 is 5 5 in base 10 while it is 101 12 in base 2 one 22 one 20 and one 2 1 Not all rational numbers can be represented with nite decimal expansions The number 1 3 for example is 333 with the bar over the 3 meaning that this digit is repeated in nitely many times The same is true for binary expansions although the numbers that require an in nite binary expansion may be di erent from the ones that require an in nite decimal expansion 5 15 1 10 in Base 2 For example the number 1 10 0 1 in base 10 has the repeating binary expansion 0 00011002 To see this one can do binary long division in a similar way to base 10 long division 1 0 1 0 0 1 0 0 0 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 0 0 0 0 1 1 0 0 1 0 0 0 6 15 Fixed Point Representation A computer word consists of a certain number of bits which can be either on to represent 1 or o to represent 0 Some early computers used xed point representation where one bit is used to denote the sign of a number a certain number of the remaining bits are used to store the part of the binary number to the left of the binary point and the remaining bits are used to store the part to the right of the binary point The di culty with this system is that it can store numbers only in a very limited range If say 16 bits are used to store the part of the number to the left of the binary point then the left most bit represents 215 and numbers greater than or equal to 216 cannot be stored Similarly if say 15 bits are used to store the part of the number to the right of the binary point then the right most bit represents 2 15 and no …

View Full Document