HP Forums

Full Version: (49G) Z->B & B->Z full Accuracy
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The 49G converts zints to hexadecimal strings by R->B, first transforming the zint to a real & thereby loosing significant digits.

This programme does Z->B & B->Z to full accuracy.

eg For input

9898989898989898979

the programme returns

# 9898989898989898979d

& applying the programme again returns the original zint.

Code:
::
  CK1&Dispatch
  # FF
  ::
    BINT64
    dostws
    FPTR2 ^DupZIsNeg?
    casedrop
    HXS 00001 0
    ZINT 18446744073709551615
    FPTR2 ^ZNMin
    DUP
    FPTR2 ^Z>R
    %>#
    DUP
    HXS>%
    FPTR2 ^R>Z
    ROT
    FPTR2 ^RSUBext
    FPTR2 ^Z>R
    % 100000000.
    DUPUNROT
    %+SWAP
    %>#
    bit%#-
    bit-
  ;
  BINT11
  ::
    BINT64
    dostws
    DUP
    HXS>%
    DUP
    FPTR2 ^R>Z
    SWAPROT
    bit%#-
    % 100000000.
    DUPUNROT
    %>#
    bit+
    HXS>%
    SWAP
    %-
    FPTR2 ^R>Z
    FPTR2 ^RSUBext
  ;
;
FWIW, I've been using the following User RPL programs for many years. They seem to work ok for inputs up to 2^64-1.

Z->B
<< "#" SWAP + "d" + OBJ-> >>

B->Z
<< PUSH DEC ->STR 3 OVER SIZE 1 - SUB OBJ-> POP >>
Great work, thank you, Joe.

Have you published these programmes previously?

You have saved me 100 Bytes of memory.
(06-02-2015 08:11 AM)Gerald H Wrote: [ -> ]Great work, thank you, Joe.
Have you published these programmes previously?

I don't think so, but the probability of my having published them and forgotten is higher than the probability of my never having published them and remembering that fact correctly. Wink
(06-02-2015 09:23 PM)Joe Horn Wrote: [ -> ]
(06-02-2015 08:11 AM)Gerald H Wrote: [ -> ]Great work, thank you, Joe.
Have you published these programmes previously?

I don't think so, but the probability of my having published them and forgotten is higher than the probability of my never having published them and remembering that fact correctly. Wink

As I get older, I find this concept applies more and more often; thanks for stating it so succinctly Joseph. Have you thought of naming this little gem, something akin to "Horn's rule"?

Oh, and the programs are truly short and sweet too. Thanks.
Reference URL's