HP Forums
(49G) Z->B & B->Z full Accuracy - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (49G) Z->B & B->Z full Accuracy (/thread-4036.html)



(49G) Z->B & B->Z full Accuracy - Gerald H - 05-31-2015 02:12 PM

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
  ;
;



RE: HP 49G: Z->B & B->Z full Accuracy - Joe Horn - 06-02-2015 05:22 AM

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 >>


RE: HP 49G: Z->B & B->Z full Accuracy - Gerald H - 06-02-2015 08:11 AM

Great work, thank you, Joe.

Have you published these programmes previously?

You have saved me 100 Bytes of memory.


RE: HP 49G: Z->B & B->Z full Accuracy - Joe Horn - 06-02-2015 09:23 PM

(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


RE: HP 49G: Z->B & B->Z full Accuracy - rprosperi - 06-03-2015 01:42 AM

(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.