Not the Coconut Grove!

Mark Power

The revival of the Coconut Grove in V18N4 made me think about those handy small programs which I have kicking about in my HP48.

1. SIGN (from comp.sys.hp48)

The HP48 version of SIGN doesn't behave the same way as SIGN on the HP41:

      HP41    HP48
X<0   -1      -1
X=0    1       0
X>0    1       1

The HP48 version works like SIGN commonly available in BASIC and other High Level Languages. If you really want the HP41 version on your HP48 the shortest I've come across is this:

<<  ARG  COS  >>

#7EFEh 15 bytes

2. LOG in other bases (from the HP48 FAQ)

To get the log in base X of Y use the following:

<<  SWAP  LN  SWAP  LN  /  >>

#3147h 22.5 bytes

3. LASTX (from the HP48 FAQ)

The HP48 provides LASTARG but not LASTX which is more familiar to owners of traditional 4 level stack RPN machines. Note that using LASTX will destoy the values held in LASTARG. This program requires LASTARG to be enabled (-55 CF):

<<  DEPTH  -> n
  <<  LASTARG  DEPTH  n  -  DUP  -> s
    <<  ROLLD  s  1  -  DROPN
    >>
  >>
>>

#BB14h 65.5 bytes

4. Binary to Gray Code (Mark Power)

Handy for computer scientists, an HP48 version of an example program seen in the HP Journal article about the HP-16C. In Gray code only one bit changes in the representation of successive numbers e.g.

Binary        Gray Code
#0001b        #0001b
#0010b        #0011b
#0011b        #0010b
#0100b        #0110b
<<  DUP  SR  XOR  >>

#8801h 17.5 bytes

5. Gray Code to Binary (Mark Power)

<<  DUP
  DO  SR  SWAP  OVER  XOR  SWAP
  UNTIL  DUP  B->R  NOT
  END  DROP
>>

#3BB9h 42.5 bytes


mark.power@btinternet.com
Page last modified : 9th May 2002