(48G/49g/50g) Fractional Base Conversions
|
10-03-2022, 10:57 PM
(This post was last modified: 10-03-2022 11:02 PM by John Keith.)
Post: #1
|
|||
|
|||
(48G/49g/50g) Fractional Base Conversions
Inspired by Gerald H's recent thread, these programs convert between integers and numbers in fractional base. The program I->FBL expects an integer n on level 3, the numerator p on level 2 and the denominator q on level 1. The program returns a list of integers representing the digits of n in base p/q, in standard order (units on the right, highest powers on the left). For example, if the level 3 argument is 15, level 2 is 3 and level 1 is 2, the result is { 2 1 0 1 0}, the digits of 15 in base 3/2. See A024629 for further information. First the program for the HP 49g and 50g, which should be used in exact mode.
Code:
The following approximate version is HP48G compatible but limited to numbers < 10^12. Code:
The next program, FBL->I converts a list as returned by the above program to an integer. The list should be on level 3, the numerator on level 2 and the denominator on level 1. For example, if the level 3 list is { 2 1 1 2 0 1 0 }, level 2 is 3 and level 1 is -2, the program returns 12, which is 2112010 in base -3/2. See A355904 and the linked paper by Knuth. Note that for negative base, the numerator must be positive and the denominator must be negative. If the signs are reversed, the result will be incorrect. Code:
For approximate mode (or the 48G), the EVAL at the end of line 3 can be eliminated. For users of the 49g or 50g with ListExt, here is a shorter and faster version: Code:
|
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
(48G/49g/50g) Fractional Base Conversions - John Keith - 10-03-2022 10:57 PM
|
User(s) browsing this thread: 1 Guest(s)