10110012-> 8910
| 1 x <- dk (move leftmost digit to x) 2 i <- k-1 (set index to next digit) 3 while i > 0 do 4 x <- di +2x (compute inner product) 5 i <- i - 1 (decrement index, end while loop) 6 stop |
x <- 1
|
Using the "place value equation":
10110012 = 1·26 + 0·25 + 1·24 + 1·23 + 0·22 + 0·21 + 1·20 =
1·64 + 0·32 + 1·16 + 1·8 + 0·4 + 0·2 + 1·1 =
64 + 0 + 0 + 16 + 8 + 1 = 8910
49710-> 1111100012
|
1 s <- 0 (starting from rightmost digit) 2 while x != 0 do 3 ds <- x mod 2 (get remainder of divide by 2) 4 x <- floor(x/2) (reset x to quotient) 5 s <- s + 1 (set up for next digit) 6 stop | 497/2 = 248 + 1 |
Using the "place value equation":
497 = 1·256 + 241 = 1·28 + 241
241 = 1·128 + 113 = 1·27 + 113
113 = 1·64 + 49 = 1·26 + 49
49 = 1·32 + 17 = 1·25 + 17
17 = 1·16 + 1 = 1·24 + 1
(several "won't go" conditions to produce 0s)
1 = 1·1 + 0 = 1·20 + 0
Write the place-value parameters top to bottom
answer = 111110001
![[Prev]](prev.gif)
![[TOC]](TOC.gif)
CS1104 Main Page
Last Updated 2001/02/05
© L.Heath, 2000, modified by J.A.N. Lee