The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





Post Reply 
HP Prime: Base 10 - Base 12 Conversions
01-31-2017, 04:20 AM
Post: #1
HP Prime: Base 10 - Base 12 Conversions
Conventions:
X = 10
E = 11
(notation by William A. Dwiggins)

HP Prime Program DEC2DUO

Enter the integer as a number.

Code:
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

Code:
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
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
HP Prime: Base 10 - Base 12 Conversions - Eddie W. Shore - 01-31-2017 04:20 AM



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