## HP15c program: number conversion binary->dec

```command         display

f LBL A        001-42,21,11
x><y         002-      34
g INT          003-   43 44
x><y         004-      34
STO .0       005-   44 .0
2            006-       2
x><y         007-      34
y^x          008-      14
+            009-      40
RCL .0       010-   45 .0
1            011-       1
0            012-       0
0            013-       0
divide       014-      10
+            015-      40
g RTN          007-   43 32
```

This program uses the following label: LBL A
The program stores intermediate results in register .0: STO/RCL .0

### Using the program

This program can convert binary numbers to decimal numbers and the binary number can have up to 99 bits althought its more practical to work with up to about 20 bits where the equivalent decimal numbers can still be shown without exponent in the display.

Before you start you put 0 in the Y register: 0 Enter. After that you specify one by one the positions where the binary number has a "1" and you press "GSB A". The LSB position is postition 0. After every run it displays the decimal sum followed by a dot and then the positions you just entered. Example: 4.02 means you just entered a 1 in position two and if you would now stop entering further positions then the decimal number would be "4".

I start every program with a label. This way you can have a number of programs in your 15c and you just run one by pressing f LABELNAME (f A) or GSB LABELNAME (GSB A).

Example:
Convert 1010010 into decimal.
 bin: 1 0 1 0 0 1 0 pos: 6 5 4 3 2 1 0
This number has in the positions 1,4,6 a one.
To start you initialize the Y register with zero, "0 Enter". After that then you run: 1 GSB A, 4 GSB A, 6 GSB A.
In other words the key sequence is:
```0
Enter
1 GSB A
4 GSB A
6 GSB A
```
Result: You see at the end 82.06 in the display. This means 1010010 binary = 82 decimal.

### Algorithm

```always add 2^(position of a 1)
```