**HP Articles Forum**

[Return to the Index ]

[ Previous | Next ]

**programming using the HP 17bii+ solver**

*Posted by Don Shepherd on 14 Apr 2007, 2:48 p.m.*

The HP 17bii+ calculator has several characteristics that might make it interesting to members of this community:

- it fits in your shirt pocket nicely
- it has a 2-line display
- it has 6 soft function keys
- it has user-definable menus
- it has a very uncluttered keyboard
- it has useful finance and business functions
- it can print using a small infrared printer
- you can use either RPN or algebraic mode
- it has 12-digit accuracy
- it has 30,740 bytes of user memory
- it is programmable
- it is still being manufactured!

I became interested in this model after reading somewhere that it was programmable. I determined that it is not “keystroke” programmable like its financial brother, the venerable 12c and its successors. But it is programmable via the built-in equation solver application.

I imagine that the original inventors of the equation solver never intended that it would be used as a general purpose “programming” language, just as the inventors of the 12c cash flow functions probably never imagined that anyone would use those financial functions for indirect addressing. But the great thing about HP calculators is that both those things are possible. And members of this community have always been willing to share insights and experiences.

So I bought the 17bii+ just to see what it could do, from a programming perspective. I knew that every programming language must support three structures: sequence, decision, and iteration (loops). So I began to look at the solver. Yep, it can do sequences (especially when you put “0X” next to things you don’t want to be included in the solution). Yep, it can do decisions (If (condition : do if true : do if false)) And yep, it can do loops (sigma function). And it can assign values to named variables (load function) and use those variables (get function) in calculations. The solver cannot use the 10 registers, but since you can create your own variable names, that is not a shortcoming. The solver cannot execute subroutines, GOTO a label or line number, or exit a loop early, and this makes it unacceptable as a general purpose programming language. But I found that you can still do some useful things with it.

For instance, you can sum the digits of a number:

sod = sigma(i:0:log(n):1:mod(ip(n):10)+0xL(n:n/10))

You can determine if a number is prime or not (a result of 0 means the number is prime, any other number is the first factor of the input number):

fact = 0xL(j:0)+ if(mod(n:2)=0:2:sigma(i:3:sqrt(n):2: if(mod(n:i)=0:if(g(j)=0:0xL(j:1)+i:0):0)))

You can calculate a standard mod-10 checkdigit (maximum 12 input digits):

ckdig = 0xL(m:2)xL(c:-1) +mod(10- mod(sigma(i:0:log(n):1: 0xL(a:mod(ip(n):10)xg(m)) +if(g(a)<10:g(a):g(a)-9) +0xL(m:g(m)+g(c)) xL(c:-g(c)) xL(n:n/10)):10):10)

You can convert from decimal to binary:

dec2bin = sigma(i:0:11:1:mod(n:2)x(10^i)+0xL(n:ip(n/2)))

Or from binary to decimal:

bin2dec = sigma(i:0:log(n):1:mod(ip(n):10)x2^i+0xL(n:n/10))

Or from decimal to octal:

dec2oct = sigma(i:0:11:1:mod(n:8)x(10^i)+0xL(n:ip(n/8))

I tried to carefully type the equations above, but I’m not perfect. If you try one of these on your 17bii+ and can’t get it to work, post a message on the forum and I’ll help.

Now, I admit that I wouldn’t attempt to do a payroll program on the 17bii+, and the lack of scientific functions would make this calculator inappropriate for many members of this community. Nevertheless, I think it is great that an application designed to solve equations can, in this case, be used for some general purpose programming tasks.

HP calculators are great!