Post Reply 
HP 50g Base Conversion
02-06-2014, 08:17 PM
Post: #1
HP 50g Base Conversion
Hello friends,

I don't know wether the HP 50g has a build in function for base conversion of integer in exact mode. The program "T2BAS" convert every number in base ten to a choosen base. The program "BAS2T" do it the other way. My programs works with a special out- and input, you kann see it below.


Stack 5: 451
Stack 4: 7
Stack 3: 7:{"1" "2" "1" "3"}
Stack 2: 7:{"1" "2" "1" "3"}
Stack 1: 451

Stack 5 shows the number 451 stack 4 the number 7 this number is the new base
on stack 3 you see the output of "T2BAS": a tagged list with the digits new based.
the tag shows you the base.
stack 2 is the input for "BAS2T" and gives you the output on stack 1.

Remark: the base and the digits are always given in base 10, the programs functioned well for example base 234 (digit range from 0 to 233) or 17 and so on.

Here is the code:

"T2BAS"

Code:
%%HP: T(3)A(R)F(,);
\<< { } \-> N NB LRES
  \<<
    WHILE N NB \>=
    REPEAT N NB IDIV2 \->STR LRES + 'LRES' STO 'N' STO
    END N \->STR LRES + NB \->TAG
  \>>
\>>

"BAS2T"

Code:
%%HP: T(3)A(R)F(,);
\<< OBJ\-> OBJ\-> 0 \-> LIN OB N
  \<<
    WHILE LIN SIZE 1 >
    REPEAT LIN DUP HEAD OBJ\-> N + OB * 'N' STO TAIL 'LIN' STO
    END LIN HEAD OBJ\-> N +
  \>>
\>>

Greetings
peacecalc
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
HP 50g Base Conversion - peacecalc - 02-06-2014 08:17 PM



User(s) browsing this thread: 1 Guest(s)