HP-67 Base Conversion from HP Key Notes
|
10-19-2015, 02:57 PM
(This post was last modified: 10-19-2015 06:35 PM by Thomas Klemm.)
Post: #2
|
|||
|
|||
RE: HP-67 Base Conversion from HP Key Notes
(10-19-2015 11:31 AM)Karl-Ludwig Butte Wrote: So my question is: Can anyone of you math gurus of this forum please explain the algorithm of this base conversion routine to me? Here are some comments to the code: Code: 001 *LBL A Thus the number is first translated from the original base to a base of \(10^m\) and then from this to the new base. These programs for the Base Conversion do a similar thing but only halfway. It's mostly only what is done in the sub-routine 0. However the algorithm used in this program could be improved a little with the following trick. Say you want to translate 23 to binary: \[ \begin{align} 23 \div 2 &= 11 & \, (1) \\ 11 \div 2 &= 5 & \, (1) \\ 5 \div 2 &= 2 & \, (1) \\ 2 \div 2 &= 1 & \, (0) \\ 1 \div 2 &= 0 & \, (1) \\ \end{align} \] The remainders are then multiplied by powers of 10 and added: \[ \begin{align} 1 \times 10^0 &= 1 \\ 1 \times 10^1 &= 10 \\ 1 \times 10^2 &= 100 \\ 0 \times 10^3 &= 0\\ 1 \times 10^4 &= 10000 \\ &= 10111 \end{align} \] We can write the remainders using the first equations: \[ \begin{align} 1 &= 23 - 2 \times 11 \\ 1 &= 11 - 2 \times 5 \\ 1 &= 5 - 2 \times 2 \\ 0 &= 2 - 2 \times 1 \\ 1 &= 1 - 2 \times 0 \\ \end{align} \] We do the same multiplication by powers of 10: \[ \begin{align} 1 \times 10^0 &= 23 \times 10^0 - 2 \times 11 \times 10^0 \\ 1 \times 10^1 &= 11 \times 10^1 - 2 \times 5 \times 10^1 \\ 1 \times 10^2 &= 5 \times 10^2 - 2 \times 2 \times 10^2 \\ 0 \times 10^3 &= 2 \times 10^3 - 2 \times 1 \times 10^3 \\ 1 \times 10^4 &= 1 \times 10^4 - 2 \times 0 \times 10^4 \\ \end{align} \] Now we can see that the same numbers appear on different lines. Thus we can re-group the sum: \[ \begin{align} & 23 \times 10^0 \\ + & 11 \times (10^1 - 2 \times 10^0) \\ + & 5 \times (10^2 - 2 \times 10^1) \\ + & 2 \times 10^3 - 2 \times 10^2) \\ + & 1 \times 10^4 - 2 \times 10^3) \\ \end{align} \] We end up with: \[ \begin{align} & 23 \\ + & 11 \times 8 \\ + & 5 \times 80 \\ + & 2 \times 800 \\ + & 1 \times 8000 \\ \end{align} \] Thus we can avoid calculating the remainders. We just need to calculate the sequence 23, 11, 5, 2, 1 and multiply by the correct factors. Kind regards Thomas |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
HP-67 Base Conversion from HP Key Notes - Karl-Ludwig Butte - 10-19-2015, 11:31 AM
RE: HP-67 Base Conversion from HP Key Notes - Thomas Klemm - 10-19-2015 02:57 PM
RE: HP-67 Base Conversion from HP Key Notes - Thomas Klemm - 10-19-2015, 04:08 PM
RE: HP-67 Base Conversion from HP Key Notes - Thomas Klemm - 10-19-2015, 06:32 PM
RE: HP-67 Base Conversion from HP Key Notes - Karl-Ludwig Butte - 10-19-2015, 07:35 PM
RE: HP-67 Base Conversion from HP Key Notes - TASP - 10-19-2015, 09:06 PM
RE: HP-67 Base Conversion from HP Key Notes - Thomas Klemm - 10-19-2015, 09:34 PM
RE: HP-67 Base Conversion from HP Key Notes - Karl-Ludwig Butte - 10-20-2015, 07:48 PM
RE: HP-67 Base Conversion from HP Key Notes - Thomas Klemm - 10-19-2015, 10:34 PM
RE: HP-67 Base Conversion from HP Key Notes - Thomas Klemm - 10-21-2015, 09:10 PM
|
User(s) browsing this thread: 2 Guest(s)