(49G) Convert Integer from Integer Base A to Integer Base B
|
07-15-2022, 10:27 AM
(This post was last modified: 10-03-2022 12:58 AM by Gene.)
Post: #1
|
|||
|
|||
(49G) Convert Integer from Integer Base A to Integer Base B
Programme inspired by the programmes here:
https://www.hpmuseum.org/forum/thread-17734.html Enter the number to be converted as a list of digits in base ten form for increasing powers of base, starting with units at the right of the list & highest power of base leftmost then the original base then the base converting to. eg The stack { 17 56 9797 4 } 18975263 18975262 will convert the level three base 18975263 number to the base 18975262 number { 17 107 9960 9874 }. Code: CKSUM # 5897h |
|||
07-15-2022, 01:09 PM
(This post was last modified: 10-02-2022 08:31 PM by John Keith.)
Post: #2
|
|||
|
|||
RE: HP 49G: Convert Integer from Integer Base A to Integer Base B
Very nice program, thanks for posting.
It could be used on older calculators for numbers < 10^12 if IDIV2 is replaced by DUP2 / FLOOR ROT ROT MOD. For users of the ListExt Library, a much shorter equivalent: Code:
|
|||
07-15-2022, 06:45 PM
Post: #3
|
|||
|
|||
RE: HP 49G: Convert Integer from Integer Base A to Integer Base B
(07-15-2022 10:27 AM)Gerald H Wrote: eg The stack We can go from base b1 to base b2, by synthetic division. b2 = b1 - 1 1 > 17 56 9797 4 1 > 17 73 9870 9874 1 > 17 90 9960 1 > 17 107 Results might require doing carries (in base b2), to limit digits = 0 .. b2-1 This avoided the steps of getting N, and the reverse of N to base b2. N = horner([17, 56, 9797, 4], b1) = 116148179948924836904678 |
|||
07-16-2022, 09:07 AM
Post: #4
|
|||
|
|||
RE: HP 49G: Convert Integer from Integer Base A to Integer Base B
Here a sys version of the programme in posting #1:
Code: Size: 99.5 |
|||
07-16-2022, 12:54 PM
(This post was last modified: 08-20-2022 04:31 AM by Gerald H.)
Post: #5
|
|||
|
|||
RE: HP 49G: Convert Integer from Integer Base A to Integer Base B
Following John's suggestion in Post #2 the programme looks like this:
Code: CKSUM # E678h This now permits the use of real numbers as a base, eg For stack { 7. 8. 9. 7. 8. 9. } 10. 1.41421356237 the programme returns { 1. .58578643763 1.17157287526 1.34314575052 1.10050506341 .44365081393 .37258300208 .47308806549 .33095244179 .53196256861 .24769132121 .64971157485 .08116908005 .88520958733 .74812459773 .94199204992 .66782207072 .0555569751 .92143057907 .69690038783 .0144340334 .97958721329 .61465450443 1.13074730184 1.40088188412 .01885391657 .9733366435 .62349427077 1.11824616226 .4185614168 1.40806519978 1.00869570886 .57348971245 1.18896429298 .31855230016 .54950146122 .22289103795 } On entering the two stack levels 1.41421356237 10. the programme then returns { 7. 8. 9. 7. 8. 9. } |
|||
10-02-2022, 08:38 PM
Post: #6
|
|||
|
|||
RE: HP 49G: Convert Integer from Integer Base A to Integer Base B
On further testing, I have determined that the correct equivalent of IDIV2 is DUP2 / FLOOR ROT ROT MOD. Using IP gives incorrect result if either integer is negative. I have updated my original post, in which I also neglected the IP (now FLOOR).
|
|||
01-06-2023, 07:02 PM
Post: #7
|
|||
|
|||
RE: (49G) Convert Integer from Integer Base A to Integer Base B
A modification of the program in post #1 which allows negative bases. The first half looks much shorter but actually takes the same number of bytes as the first half of the original program.
Code:
Also an approximate number version which is larger but runs on any RPL calculator. The first half is similar to my program DL→I in this thread. Code:
|
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)