Docsity

Repeating Binary Fractions - Computer and Numerical Algorithms, Assignment 2 | MATH 248, Assignments of Mathematics

Toggle sidebar
bg1
Math 248 Computers and Numerical Algorithms–Tongen/Pruett
Graded HW ASSIGNMENT 2:
Repeating Binary Fractions
ASSIGNED: Thursday, 12 February, 2009 Due: Monday, 16 February, 2009
Background: Consider that (0.1)10, which terminates as a decimal fraction, repeats as a binary frac-
tion; that is,
(0.1)10 = (0.00011 0011 0011 0011)2(1)
To derive this result, we use ALG 1.3 from the course notes (Base 10 to Base bFractions). On the other
hand
(1/3)10 =0.3333310 = (0.01 01 01 01)2(2)
repeats as both decimal and binary fractions, whereas
(1/16)10 = (0.0625)10 = (0.0001)2(3)
terminates as both decimal and binary fractions.
Of interest in this assignment is the reverse process. That is, given a binary fraction, repeating or
terminating, can we derive the corresponding decimal fraction, repeating or terminating? If the binary
fraction terminates, the problem is easy. We simply move the “decimal point” nplaces to the right, just
enough places to get a whole number, convert the whole number using ALG 1.1 (Horner’s method),
and divide the result by 2n. On the other hand, if the binary fraction repeats, we have to be more clever.
It was shown in class that a repeating “decimal” fraction is really a geometric series in disguise. Geo-
metric series are nice, because, although they are infinite, we can sum them exactly. In particular, the
geometric series ∞
∑
k=0
ark=a+ar +ar2+ar3+... =a
1−r
provided |r|<1. Let’s illustrate by working backwards from Eq. 2. We do this by considering the
value of each repetition of the block of repeated bits. Let Bbe the block size. In this example, two bits
are repeated, so B=2. Now consider each block in turn: Before proceeding further, see if you can fill
Block number Binary Value Decimal Value
1.01 1/4
2.00 01 =.01 ×2−21/4×2−2
3.00 00 01 =.01 ×2−41/4×2−4
. . .
. . .
. . .
Table 1: Repeating binary fractions as geometric series.
in the 4th row in the Table 1. Note that the Table is infinite, but by row 4 the pattern should be clear.
Adding down the second and third columns, we get
(0.01 01 01 01)2=1/4+1/4×2−2+1/4×−4+1/4×2−6+...
=1/4[1+ (1/4)+(1/4)2+ (1/4)3+...](4)
pf2

Partial preview of the text

Download Repeating Binary Fractions - Computer and Numerical Algorithms, Assignment 2 | MATH 248 and more Assignments Mathematics in PDF only on Docsity!

Math 248 Computers and Numerical Algorithms–Tongen/Pruett

Graded HW ASSIGNMENT 2: Repeating Binary Fractions

ASSIGNED: Thursday, 12 February, 2009 Due: Monday, 16 February, 2009

Background: Consider that ( 0. 1 ) 10 , which terminates as a decimal fraction, repeats as a binary frac- tion; that is, ( 0. 1 ) 10 = ( 0 .00011 0011 0011 0011) 2 (1)

To derive this result, we use ALG 1.3 from the course notes (Base 10 to Base b Fractions). On the other hand ( 1 / 3 ) 10 = 0. 3333310 = ( 0 .01 01 01 01) 2 (2)

repeats as both decimal and binary fractions, whereas

( 1 / 16 ) 10 = ( 0. 0625 ) 10 = ( 0. 0001 ) 2 (3)

terminates as both decimal and binary fractions.

Of interest in this assignment is the reverse process. That is, given a binary fraction, repeating or terminating, can we derive the corresponding decimal fraction, repeating or terminating? If the binary fraction terminates, the problem is easy. We simply move the “decimal point” n places to the right, just enough places to get a whole number, convert the whole number using ALG 1.1 (Horner’s method), and divide the result by 2n. On the other hand, if the binary fraction repeats, we have to be more clever.

It was shown in class that a repeating “decimal” fraction is really a geometric series in disguise. Geo- metric series are nice, because, although they are infinite, we can sum them exactly. In particular, the geometric series ∞

k= 0

ark^ = a + ar + ar^2 + ar^3 + ... =

a 1 − r

provided |r| < 1. Let’s illustrate by working backwards from Eq. 2. We do this by considering the value of each repetition of the block of repeated bits. Let B be the block size. In this example, two bits are repeated, so B = 2. Now consider each block in turn: Before proceeding further, see if you can fill

Block number Binary Value Decimal Value

  1. 01 1 / 4 2 .00 01 =. 01 × 2 −^2 1 / 4 × 2 −^2 3 .00 00 01 =. 01 × 2 −^4 1 / 4 × 2 −^4

... ... ...

Table 1: Repeating binary fractions as geometric series.

in the 4th row in the Table 1. Note that the Table is infinite, but by row 4 the pattern should be clear. Adding down the second and third columns, we get

( 0 .01 01 01 01) 2 = 1 / 4 + 1 / 4 × 2 −^2 + 1 / 4 ×−^4 + 1 / 4 × 2 −^6 + ... = 1 / 4 [ 1 + ( 1 / 4 ) + ( 1 / 4 )^2 + ( 1 / 4 )^3 + ...] (4)

The series on the right is geometric, with a = 1 /4 and r = 1 /4. Thus it converges to

a 1 − r

Voila! We’ve now successfully gone both directions in converting fractions between binary and decimal representations.

Assignment: Your job is to fill in Table 2 below and to notice patterns. For this purpose, recall that B represents the length of the block of repeating bits. So, B = 1 means that the repetition block has only 1 bit, (e.g., ( 0. 111111 ) 2 ), B = 2 means that the repetition block has 2 bits (e.g., (. 01010101 ) 2 ), and so on. For the moment, assume that only a single bit in the block can be non-zero, and let N denote its position in the block of the “1” bit. For the latter example immediately above, N = 2. Thus we have entered the value 1/3 obtained from Eqs. 4 and 5 in the column corresponding to B = 2 and in the row corresponding to N = 2. Note that the “x’s” in the Table denote impossible combinations. A couple of values have been computed for you so you will know if you are doing the assignment correctly.

  1. Complete the Table.
  2. Based on the observed pattern, find a general expression for Row N = 1 of the Table in terms of B.
  3. What is the relationship between the values in Row N = 1 and those in Row N = 2? Between Row N and Row N + 1, in general? Explain why.
  4. Based on the patterns, extend the Table to incorporate Column B = 6 and Row N = 6 without doing any additional work.
  5. What if more than one bit in a block is non-zero? No problem. For example, if B = 3, with non-zero bits in the 2nd and 3rd locations of the block, simply add the numbers in column B = 3 for N = 2 and N = 3. OK then. Use this rubric to compute the decimal equivalent of ( 0 .000111 000111 000111 2.

N ↓ \B → 1 2 3 4 5

2 x 1/ 3 x x 4 x x x 5 x x x x

Table 2: Interpreting repeating binary fractions.

GROUND RULES: You may work with others, but you are to turn in this assignment individually.