Saturday, February 4, 2017

HP Prime: Base Conversions – Joe Horn

HP Prime:  Base Conversions – Joe Horn

Special thanks to Joe Horn.  When I posted the conversion programs ( ), Horn alerted me to a hidden convert command where we can convert base integers.

The HP Prime has a CONVERT (upper case letters) that converts units (i.e. length, volume, etc.).  However, for the base to work, not only convert has to be typed in lower case letters, AND it is a CAS command.

The syntax that Joe told me is:

Decimal to Other Base (D2B)

convert(number in base 10, base, desired base)

The word base is typed in lowercase.  The result is a vector of digits but the order goes from lower power to upper power.  The number will be written backwards.  To get it in proper order:

REVERSE(convert(number in base 10, base, desired base))

In Home mode or in programming, you will need a CAS command attached to the syntax.

Other Base to Decimal

convert(vector of digits, base, base that is represented)

Again, going this way the vector of digits goes from lower to upper power.  The proper order requires the following:

convert(REVERSE(vector of digits), base, base that is represented)

Once again, in Home mode or in programming, you will need a CAS command attached to the syntax.

Below are programs that help accomplish these tasks:

HP Prime Program D2B (decimal to base)

// decimal to base
// Joe Horn

Example:  D2B(17291, 12) returns [10 0 0 11]   (A00B_12)

HP Prime Program B2D (base to decimal)

// vector (decr),base to base 10
// Joe Horn


Example:  B2D([1, 0, 1, 6, 2, 5], 7) returns 17463.  (101625_7)

Thank you Joe!  As Joe Horn always says, Happy Programming!


This blog is property of Edward Shore, 2017.


  1. See the profiles of experts named Eddie Choufi on twitter. There are 3 experts named Eddie Choufi, who utilize twitter to trade data. See what Eddie choufi (eddiechoufi) has found on twitter, the world's greatest gathering of the loved and admired things.

  2. Hi, I added a bit to render the output more readable aka useful.
    See below :

    EXPORT Dec2Base(n,b)
    LOCAL r := iPart(ROUND(n,0));
    RETURN CAS("char(apply((x)->PIECEWISE(10>x,x+48,x≥10,x+55),REVERSE(convert(r,base,b))))");

    EXPORT Base2Dec(n,b)
    RETURN CAS("convert(apply((x)->PIECEWISE(58>x,x-48,x≥58,x-55),REVERSE(ASC(n))),base,b)");

    I guess, it could be improved further. Cheers


HP Prime and Casio fx-CG50: Trapezoid Midsegment, Height, Area

HP Prime and Casio fx-CG50:  Trapezoid Midsegment, Height, Area The program TRAPEZ calculates the following: Midsegment leng...