(28/48/50) Mixed-Radix conversion programs - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (28/48/50) Mixed-Radix conversion programs (/thread-19516.html) |
(28/48/50) Mixed-Radix conversion programs - John Keith - 02-05-2023 07:49 PM These programs facilitate the conversion of numbers to and from mixed-radix bases. The inspiration came from this post by Thomas Klemm, as well as several related commands from the Wolfram Language (Mathematica). The first program, MXRAD is similar to the Mathematica command IntegerDigits with the MixedRadix option. See the 3rd example here. Level 2 should have the number to be converted; level 1 should have a list of the radices ordered from most significant to least. For the 49g and 50g in exact mode, the phrase DUP2 / FLOOR ROT ROT MOD can be replaced with IDIV2, allowing the use of arbitrarily large integers. Code:
The second program, MX→N, is the inverse of the program above. It is similar to the Mathematica command FromDigits with the MixedRadix option. The level 2 object should be a list of the form returned by MXRAD; the level 1 object should be a list of radices such as the level 1 list given to MXRAD. The level 2 list should have one more element than the level 1 list. Code:
The third program, DCOMP is similar to the Mathematica command NumberDecompose. However, the final 1 in the level 1 list is not used. As one can see, this is very similar to MXRAD except that the radices in the MXRAD list are the partial sums of the factors in the list for DCOMP. The number on level 2 need not be an integer- see the first example in the previous link. Code:
The final program, NCOMP, is the inverse of DCOMP. It is similar to the Mathematica command NumberCompose. As before, the level 2 list is of the form returned by DCOMP. The level 1 list is of the form given to DCOMP, again without the final 1. Code:
|