SLIDE 1
AMTH140 Lecture 20 Radix Conversion Slide 1 April 10, 2006 - - PDF document
AMTH140 Lecture 20 Radix Conversion Slide 1 April 10, 2006 - - PDF document
AMTH140 Lecture 20 Radix Conversion Slide 1 April 10, 2006 Reading: Lecture Notes 14.2 Radix Conversion Radix conversion means converting a number between one base and another. Base p numbers are written ( a n a n 1 . . . a 1 a 0 .b 1
SLIDE 2
SLIDE 3
Slide 5 The Division Algorithm This is used to convert a decimal integer to base p. For integer a, its base p representation (rmrm−1 . . . r1r0)p is calculated by successive division by p: a = q0p + r0 0 ≤ r0 < p q0 = q1p + r1 0 ≤ r1 < p q1 = q2p + r2 0 ≤ r2 < p . . . qm−1 = qmp + rm 0 ≤ rm < p Slide 6 The algorithm terminates when we get a quotient qm = 0. The remainders (in reverse order) constitute the base p digits of a. To convert 2345 to base 11: 2345 = 213 · 11 + 2 213 = 19 · 11 + 4 19 = 1 · 11 + 8 1 = 0 · 11 + 1 We have reached a quotient of 0, so 2345 = (1842)11 3
SLIDE 4
Slide 7 To check this note: 1 · 113 + 8 · 112 + 4 · 11 + 2 = 2345 Convert 1234 to hexadecimal (base 16) 1234 = 77 · 16 + 2 77 = 4 · 16 + 13 4 = 0 · 16 + 4 So 1234 = (4D2)16 (n.b. D is the hexadecimal representation of 13.) Slide 8 Convert 1234 to binary (base 2) 1234 = 617 · 2 + 0 617 = 308 · 2 + 1 308 = 154 · 2 + 0 154 = 77 · 2 + 0 77 = 38 · 2 + 1 38 = 19 · 2 + 0 19 = 9 · 2 + 1 9 = 4 · 2 + 1 4 = 2 · 2 + 0 4
SLIDE 5
Slide 9 2 = 1 · 2 + 0 1 = 0 · 2 + 1 So 1234 = (10011010010)2 Note that once we have converted to binary or hexadecimal, converting to the other is easy using the method of the previous lecture: 1234 = (100 1101 0010)2 = (4D2)16 Slide 10 Integer and Fractional Parts Any decimal number x can be written a = Integer Part + Fractional Part = ⌊a⌋ + f For example if a = 123.456 then ⌊a⌋ = 123, so that 123 is the integer part of a. The fractional part of a is .456. 5
SLIDE 6
Slide 11 Conversion of the Fractional Part Conversion of the fractional part (i.e. the part after the decimal point) of a decimal number to base p is achieved by taking the integer and fractional parts on successive multiplication by p. Start with a fractional part f of a decimal number: p · f = i1 f1 p · f1 = i2 f2 p · f2 = i3 f3 . . . Slide 12 The base p representation of f is f = (0.i1i2 . . . in . . . )p If the fractional part at any step is zero, the algorithm terminates and f has a finite expansion in base p. Otherwise the algorithm can be continued forever and f has an infinite expansion like (1/3)10 = 0.333333 . . .. 6
SLIDE 7
Slide 13 Convert 0.8125 to base 4: 4 × 0.8125 = 3 .25 4 × 0.25 = 1 .00 The fractional part is zero, so the algorithm terminates and 0.8125 = (0.31)4 To check this (0.31)4 = 3 · 4−1 + 1 · 4−2 = 3 4 + 1 16 = 0.8125 Slide 14 Convert 0.1 to binary 2 × 0.1 = .2 2 × 0.2 = .4 2 × 0.4 = .8 2 × 0.8 = 1 .6 2 × 0.6 = 1 .2 2 × 0.2 = .4 2 × 0.4 = .8 7
SLIDE 8
Slide 15 2 × 0.8 = 1 .6 2 × 0.6 = 1 .2 2 × 0.2 = .4 2 × 0.4 = .8 There is an obvious repetition here so 0.1 = (.00011001100 . . .)2 a non-terminating decimal expansion. Slide 16 Convert 156.32 to hexadecimal. We do the integer and fractional parts separately: 156 = 9 · 16 + 12 9 = 0 · 16 + 9 So the integer part is (9C)16. 8
SLIDE 9