Another Algorithm for Converting to Binary
Adapted from a brief paper Al wrote and June showed Mary:
BH's response to a discussion with Mary, in which we agreed that the algorithm currently on the student lab page is best for students preparing to do conversion on paper on the exam (Mary appreciates the elegance of the recursive algorithm for programming base conversion procedure(s), wants to use it in U4 as part of the cross-course recursion theme, and asked Brian to explain how he would make the recursive algorithm accessible):
- Draw a line separating the last digit from the butlast.
- The contribution of the last digit is just itself.
- Now look at the bl. As usual with recursion, just take on faith that the procedure can solve this smaller problem. It gives you the answer xxx. Is that the contribution of the bl to the result? No, we have to take into account that the bl is shifted left by a digit, so it really represents xxx*the base (let's say 2 but I'd start with a different one because we don't want them to think that the algorithm is specially connected to how
computers work).
- I disagree here. Unless we are getting into optional/TIF territory, I would stick to 2 to 10 and 10 to 2 and just say that the same alg works for other bases (maybe even show an example like the code for
() base 7
or something). Then we can offer non dec/bin stuff as optional/TIF. --MF, 4/23/19
- So, (recur (bl numeral))*base + (last numeral).
- Then the base case is length=1, so result=input.
All this depends on them knowing bl and abl, which they don't. Is U4 going to be the introduction to those ideas? Can we really do this in U4? Can it actually be required content? I'm not as sure that here and required is right as I was a few days ago. --MF, 4/23/19