## Monday, January 30, 2017

### HP Prime and TI-84 Plus CE: Base 10 (Decimal)-Base 12 (Duodecimal/Dozenal) Conversions

HP Prime and TI-84 Plus CE:  Base 10 (Decimal)-Base 12 (Duodecimal/Dozenal) Conversions

Conventions:
X = 10
E = 11
(notation by William A. Dwiggins)

HP Prime Program DEC2DUO

Enter the integer as a number.

EXPORT DEC2DUO(n)
BEGIN
// integer
// EWS 2017-01-30
// base 10 to base 12
LOCAL s,d,k,q,str1;
s:=IP(LN(n)/LN(12))+1;
d:=n;
str1:=":";

FOR k FROM 1 TO s DO
q:=IP(d/12^(s-k));

IF q<10 THEN
str1:=str1+STRING(q);
END;
IF q==10 THEN
str1:=str1+"X";
END;
IF q==11 THEN
str1:=str1+"E";
END;

d:=d-q*12^(s-k);
END;

RETURN MID(str1,2,s+1);
END;

Example:  Convert 12501 from Base 10 to Base 12
DEC2DUO(12501) returns “7299”

HP Prime DUO2DEC

Enter the integer as a string, use X for 10 and E for 11

EXPORT DUO2DEC(str1)
BEGIN
// as a string, X=10, E=11
// 2017-01-30 EWS
// base 12 to base 10
LOCAL s,n,k,str2,q;

s:=DIM(str1);
n:=0;

FOR k FROM 1 TO s DO
str2:=MID(str1,k,1);
q:=EXPR(str2);
IF str2=="X" THEN
q:=10;
END;
IF str2=="E" THEN
q:=11;
END;
n:=n+q*12^(s-k);
END;

RETURN n;
END;

Example:  Convert X2X3 from base 12 go base 10
DUO2DEC(“X2X3”) returns 17691

Note that the latest version (as of 1/30/2017) of the TI-84 Plus CE operating system is used.

TI-84 Plus CE Program DEC2DUO

Input "DEC: ",N
iPart(ln(N)/ln(12))+1→S
DelVar Str1
":"→Str1
N→D
For(K,1,S)
int(D/12^(S-K))→Q
If Q<10
Str1+eval(Q)→Str1
If Q=10
Str1+"X"→Str1
If Q=11
Str1+"E"→Str1
D-Q*12^(S-K)→D
End
sub(Str1,2,length(Str1)-1)→Str1
Disp ">DUO"
Pause Str1

Example:  5825 in base 10, result is 3455 in base 12

TI-84 Plus CE Program DUO2DEC

Disp "X=10, E=11"
Disp "DON'T INCLUDE QUOTES"
Input "DUO: ",Str1
length(Str1)→S
0→N
For(K,1,S)
sub(Str1,K,1)→Str2
expr(Str2)→Q
If Str2="X":10→Q
If Str2="E":11→Q
N+Q*12^(S-K)→N
End
Disp ">DEC"
Pause N

Example:  3EE1 in base 12, result is 6901 in base 10

This blog is property of Edward Shore, 2017