(28/48/50) Base Conversion Programs
|
01-02-2023, 07:21 PM
(This post was last modified: 02-14-2023 05:48 PM by John Keith.)
Post: #1
|
|||
|
|||
(28/48/50) Base Conversion Programs
These two simple programs convert integers to and from lists of digits in any base. The integers, the base and the digits may be positive or negative.
The first program takes an integer on level 2 and an integer base on level 1 and returns the digits as a list. I call the program I→DL to avoid conflict with the similar ListExt command I→BL. In exact mode on the HP 49 and 50, the size of the integer and the base are limited only by memory. Important note: If the base is positive, the level 2 integer must be positive, otherwise the program will crash with an Insufficient Memory error. Code:
Also an approximate version for the HP-28 and 48. Code:
The next program takes a list of integers on level 2 and the base on level 1 and returns an integer. The base may be negative or complex, and on the 49 and 50 it can be symbolic- given 'X' as the base it will return a polynomial in X. It runs without modification on any RPL calculator. Called DL→I for reason given above. Code:
A shorter version for HP 48G and later: Code:
Updated 1/03/2023 with improved I→DL programs. Updated 1/04/2023 with additional note and program. |
|||
02-14-2023, 05:54 PM
Post: #2
|
|||
|
|||
RE: (28/48/50) Base Conversion Programs
Important update fixing a bug where DL→I would crash if the level 1 list had only 1 object. Also changed OBJ→ to LIST→ for HP-28 compatibility.
|
|||
02-15-2023, 03:58 AM
(This post was last modified: 02-15-2023 03:59 AM by Gerald H.)
Post: #3
|
|||
|
|||
RE: (28/48/50) Base Conversion Programs
This programme also does the job
https://www.hpmuseum.org/forum/thread-40...light=XdYB For input 75 1 11 the programme returns 11: {6 9 "."} For -75 1 11 returns 11: {-6 -9 "."} For 75 1 -11 returns -11: {-6 9 "."} & for -75 1 -11 returns -11: {6 -9 "."} |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)