Post Reply 
(49G) Z->B & B->Z full Accuracy
05-31-2015, 02:12 PM (This post was last modified: 06-15-2017 01:42 PM by Gene.)
Post: #1
(49G) Z->B & B->Z full Accuracy
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
  ;
;
Find all posts by this user
Quote this message in a reply
06-02-2015, 05:22 AM
Post: #2
RE: HP 49G: Z->B & B->Z full Accuracy
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 >>

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
06-02-2015, 08:11 AM
Post: #3
RE: HP 49G: Z->B & B->Z full Accuracy
Great work, thank you, Joe.

Have you published these programmes previously?

You have saved me 100 Bytes of memory.
Find all posts by this user
Quote this message in a reply
06-02-2015, 09:23 PM
Post: #4
RE: HP 49G: Z->B & B->Z full Accuracy
(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

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
06-03-2015, 01:42 AM
Post: #5
RE: HP 49G: Z->B & B->Z full Accuracy
(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.

--Bob Prosperi
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)