# HP Forums

Full Version: HEX-DEC converter for 33E/33C
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

Here is a program that I wrote several years ago and just found recently. I posted it to the museum curator, but it has not been posted in the programs section yet.

Best Wishes all,
Glenn

-------------
Program for the HP 33E and HP-33C

HEX to DECIMAL
DECIMAL to HEX

by: Glenn Hayhurst - Longmont CO

This program will convert DECIMAL numbers
in the range of 0-65535 to their HEX
equivalents.

It will also convert HEX numbers in the
range of 0-FFFF to their DECIMAL equivalents.

Program Listing

Key Display

_______________

ENTER 01-31

RCL 5 02-24 5

/ 03-71

g INT 04-32

STO 1 05-23 1

RCL 5 06-24 5

* 07-61

- 08-41

ENTER 09-31

ENTER 10-31

RCL 6 11-24 6

/ 12-71

g INT 13-15 32

STO 2 14-23 2

RCL 6 15-24 6

* 16-61

- 17-41

ENTER 18-31

ENTER 19-31

RCL 7 20-24 7

/ 21-71

g INT 22-15 32

STO 3 23-23 3

RCL 7 24-24 7

* 25-61

- 26-41

g INT 27-15 32

STO 0 28-23 0

RCL 1 29-24 1

f PAUSE 30-14 74

RCL 2 31-24 2

f PAUSE 32-14 74

RCL 3 33-24 3

f PAUSE 34-14 74

RCL 0 35-24 0

GTO 00 36-13 00

RCL 1 37-24 1 <-Entry point for H>D conversion

RCL 5 38-24 5

* 39-61

STO + 0 40-23 51 0

RCL 2 41-24 2

RCL 6 42-24 6

* 43-61

STO + 0 44-23 51 0

RCL 3 45-24 3

RCL 7 46-24 7

* 47-61

STO + 0 48-23 51 0

RCL 0 49-24 0

-------------------

Enter the program, then store these three
values that are used in the calculations.

4096 STO 5

256 STO 6

16 STO 7

-------------------
Before running the program for the first
time, hit g RTN. This sets the program
to step 00.
-------------------

Example:

To convert from DECIMAL to HEX:

43961 ENTER (stores value in Y register)
R/S (run program)

The display will pause with four numbers.
These numbers appear in the order of the
hex value.

10 11 11 9 (Display shows)

A B B 9 (Hex Value)

--------------------

Example:

To convert from HEX to DECIMAL:

Store the hex values in the following
registers.

I.E. ( HEX ) A B B 9

(DEC equiv) 10 11 11 9

10 STO 1

11 STO 2

11 STO 3

9 STO 0

Then: GSB 37 (entry point for H>D conversion)

The program will run converting the values stored
in registers 1, 2, 3, 0 to a decimal value that is
left in the X register (display).

--------------------

Number conversion table:

HEX DECIMAL
--- -------
0 0

1 1

2 2

... ...

9 9

A 10

B 11

C 12

D 13

E 14

F 15

--------------------

Registers used:

R0 HEX digit

R1 HEX digit

R2 HEX digit

R3 HEX digit

R4 unused

R5 4096 fixed value for program

R6 256 fixed value for program

R7 16 fixed value for program

Edited: 3 May 2006, 10:12 a.m. after one or more responses were posted

It looks like the forum truncated all the carriage returns in the program listing. The original listing showed the KEY and then the KEY CODES.

I hope you all can sort it out.

If I remember right the 33E and the 25 had almost identical programming and this should work on either calculator.

Regards,
Glenn

Hi, Glenn:

Try this: include all your formated listings between a pair of [PRE]..[/PRE] tags, like this:
``` [pre]
cucu
cantaba
la
rana
[/pre]
```

and your formatting will be preserved exactly as entered, carriage returns, warts and all.

Best regards from V.

Hi;

based on what Valentin has already posted, I guess you would like to see your listing like this:

```Program Listing
Key	Display
_______________
ENTER	01-31
RCL 5	02-24 5
/	03-71
g INT	04-32
STO 1	05-23 1
RCL 5	06-24 5
*	07-61
-	08-41
ENTER	09-31
ENTER	10-31
RCL 6	11-24 6
/	12-71
g INT	13-15 32
STO 2	14-23 2
RCL 6	15-24 6
*	16-61
-	17-41
ENTER	18-31
ENTER	19-31
RCL 7	20-24 7
/	21-71
g INT	22-15 32
STO 3	23-23 3
RCL 7	24-24 7
*	25-61
-	26-41
g INT	27-15 32
STO 0	28-23 0
RCL 1	29-24 1
f PAUSE	30-14 74
RCL 2	31-24 2
f PAUSE	32-14 74
RCL 3	33-24 3
f PAUSE	34-14 74
RCL 0	35-24 0
GTO 00	36-13 00
RCL 1	37-24 1   <-Entry point for H>D conversion
RCL 5	38-24 5
*	39-61
STO + 0	40-23 51 0
RCL 2	41-24 2
RCL 6	42-24 6
*	43-61
STO + 0	44-23 51 0
RCL 3	45-24 3
RCL 7	46-24 7
*	47-61
STO + 0	48-23 51 0
RCL 0	49-24 0
-------------------```
Enter the program, then store these three values that are used in the calculations.
```
4096	STO 5
256	STO 6
16	STO 7
-------------------```
Before running the program for the first time, hit g RTN. This sets the program to step 00.

Example:

To convert from DECIMAL to HEX:

```
43961	ENTER	(stores value in Y register)
R/S		(run program)```

The display will pause with four numbers. These numbers appear in the order of the hex value.

```
10	11	11	9	(Display shows)
A	 B	 B	9	(Hex Value)
--------------------```

Example:

To convert from HEX to DECIMAL:

Store the hex values in the following registers.

```
I.E.	(   HEX   )	 A	 B	B	9
(DEC equiv)	10	11	11	9
10	STO 1
11	STO 2
11	STO 3
9	STO 0```

Then: GSB 37 (entry point for H>D conversion)

The program will run converting the values stored in registers 1, 2, 3, 0 to a decimal value that is left in the X register (display).

```
--------------------```

Number conversion table:

```HEX	DECIMAL
---	-------
0	 0
1	 1
2	 2
...	 ...
9	 9
A	10
B	11
C	12
D	13
E	14
F	15
--------------------
Registers used:
R0	HEX digit
R1	HEX digit
R2	HEX digit
R3	HEX digit
R4	unused
R5	4096	fixed value for program
R6	 256	fixed value for program
R7	  16	fixed value for program```

Hope this is what you had in mind.

Luiz (Brazil)

Hello Glenn,

Thanks for sharing your program with us. Here is mine (not optimized as yours, since unlike you I was not limited by memory on the 15C back then):

```----------------------------------
HEX2DEC
f LBL D
STO 5 1 + g LOG 2 /
STO 6 0 STO I STO 7
f LBL 3
RCL 5 g INT 100 /
STO 5 f FRAC 100 * 15
g TEST 8 GTO 2
Rv 16 RCL I y^x * STO + 7
1 STO + I RCL I RCL 6
g TEST 7 GTO 3
RCL 7
g RTN
f LBL 2
g SF 9 R/S g CF 9 R/S

DEC2HEX
f LBL E
STO 1 0 STO I STO 2
f LBL 4
RCL 1 g INT 16 /
STO 1 f FRAC 16 *
RCL I 10^x * STO + 2
2 STO + I RCL 1
g TEST 0 GTO 4
RCL 2
g RTN

(g TEST 0: x!=y)
(g TEST 7: x>y )
(g TEST 8: x<y )
----------------------------------
f FIX 0
43961      f E => 10,111,109. (10.11.11.09, that is, ABB9)
10111109   f D => 43,961.
1521       f E => 51,501.     (05.15.01, or 5F1)
1615       f D => 15. (blinking, 16 not allowed)
R/S
1515       f D => 255.
1515151515 f D => 1,048,575.
```

A 16C would have been of help :-)

Quote:
If I remember right the 33E and the 25 had almost identical programming and this should work on either calculator.

The 25 has no GSB/RTN, and more limited statistics (Sigma+ does not sum Y^2, mean and standard deviation are calculated for X only, and there's no linear regression, correlation coefficient, and linear estimates). Also, the statistical summations are stored in different registers. As long as you don't use subroutines (not all that useful on a machine with only 49 program steps, anyway) or statistics, programs will port to the 25 just fine.

But, the 33E/C also has degrees/radians conversions, which the 25 does not have, and the inequality comparison functions are different (33E/C: X<=Y, X>Y, X>0; 25: X<Y, X>=Y, X>=0). Those differences can be a problem (but the HEX/DEC conversion program is not affected).

For your program, the only difference is that instead of GSB 37, an HP-25 user will have to do GTO 37 R/S.

BTW, I think I still have an any-base-to-any-base conversion program for the HP-25 lying around somewhere. Works on integers only, bases 2-100, and for bases 11-100 you're limited to 5-digit numbers. If anyone's interested I'll dig it up. If I can't find it, maybe I'll try to rewrite it -- nice excuse to get that dusty HP-25 out of that drawer. :-)

- Thomas

Edited: 4 May 2006, 8:09 a.m.

Hi, Thomas:

Thomas posted:

"As long as you don't use subroutines (not all
that useful on a machine with only 49 program steps, anyway)"

Quite the opposite. The HP-25 was my very first HP machine, 30+ years ago, and I vividly remember the one feature I missed out the most was precisely the lack of subroutine capability. Many of my programming needs at that time just required calling subroutines because some function, say, had to be evaluated from different places and with different arguments, and mimicking that with just conditionals and GTO's was really nightmarish at times (if fun :-)

The most difficult example I remember was trying to implement a 4th- order Runge-Kutta algorithm to solve first-order differential equations. That required calling a function of two variables, f(x,y), no less than 4 times, each time with different arguments. Managing to do that (i.e., calling the function f(x,y) four times while always returning to the proper sequence in the algorithm) without subroutine capability, in just 49 steps, while also leaving sufficient steps (say 10 or more) to define f(x,y) itself, was quite a programming feat. On the other hand, having subroutine capability, it becomes an utterly trivial task.

You can see the exact details of the implementation of 3rd- and 4th-order Runge-Kutta methods, plus a fond remembrance of the HP-25 and several fully worked out examples in my recent, 7-page Datafile article Long Live the HP-25 !

"BTW, I think I still have an any-base-to-any-base conversion program for the HP-25 lying around somewhere. Works on integers only, bases 2-100, and for bases
11-100 you're limited to 5-digit numbers."

A similar program to the one you describe was featured in the very HP-25 Applications Manual, which came with every HP-25. I don't remember the exact details, but I think there were two programs, one for integer parts, the other for decimal parts. By using both, you could convert an arbitrary floating-point number from one base (2-100) to another.
Best regards from V.

Edited: 4 May 2006, 8:42 a.m.

I stand corrected -- apparently GSB/RTN are useful even on a humble 49-step machine!

Regarding the base conversion programs in the HP-25 Applications Programs book: there are two programs, one for base b to base 10, the other for base 10 to base b. Both handle integers *and* fractions, but they are awkward to use (one requires you to enter the digits separately, the other displays successive approximations but does not terminate automatically).

I don't know if any-base-to-any-base for integers *and* fractions can be squeezed into 49 lines... I couldn't do it in 1977, but hey, I was only 12 at the time. Maybe I could come up with something better today. Apart from simply using my HP-42S, of course. :-)

- Thomas

Appears to work very nicely on an HP25.

Mike T.

Thanks to everyone on their input on my program. I've been watching the forum for quite some time now. I'm glad that I could finally contribute something. I hope someone finds it useful. I also own a 41CX, card reader, printer, Advantage ROM, Aviation ROM, and X-Memory module. ;-)

Glenn