HP Forums
(50G) Integer to Hexadecimal Character String & Back - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (50G) Integer to Hexadecimal Character String & Back (/thread-4058.html)



(50G) Integer to Hexadecimal Character String & Back - Gerald H - 06-02-2015 05:23 PM

The programme takes integer input & returns a character string of the hexadecimal value.

eg For input

18188037387806198379277339915556929647807403283187048631478337739929618787870634​227045716719924575689062274471430368865388203540672666042530996797

the programme returns

"5D3841172E8C2C2D55139C62DE05E1797BD976F2262E5225FC09438286F819EBF3A25CC8A629D8CC​762CB9D45A75B95074F2E0F7D47BDDDFC3157223D"

& applied to the result returns the original integer value.

Code:
::
  CK1&Dispatch
  # FF
  ::
    FPTR2 ^DupQIsZero?
    casedrop
    "0"
    FPTR2 ^Z>ZH
    FPTR 4 7
    BINT64
    BINT58
    DO
    INDEX@
    DUP
    #>CHR
    CHR>$
    SWAP
    #7+
    #>CHR
    CHR>$
    FPTR F 1A
    DROPLOOP
  ;
  BINT3
  ::
    DUPNULL$?
    caseSIZEERR
    DUP
    CAR$
    CHR_-
    EQUAL
    ITE
    ::
      CDR$
      TRUE
    ;
    FALSE
    SWAP
    Z0_
    SWAP
    DUPLEN$
    #1+_ONE_DO
    DUPINDEX@
    SUB$1#
    BINT48
    #-DUP
    BINT9
    #>
    IT
    #7-_
    FPTR2 ^#>Z
    ROT
    ZINT 16
    FPTR2 ^RMULText
    FPTR2 ^RADDext
    SWAPLOOP
    DROPSWAP
    NOT?SEMI
    FPTR2 ^RNEGext
  ;
;