(50) Any integer from base a to base b, a&b free

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (https://www.hpmuseum.org/forum/forum-10.html)
+--- Forum: General Software Library (https://www.hpmuseum.org/forum/forum-13.html)
+--- Thread: (50) Any integer from base a to base b, a&b free (/thread-24325.html)



(50) Any integer from base a to base b, a&b free - Gil - 2025-12-01 17:02

Version 5

Note 
When in presence of fractions (real numbers), 
only the integer part is considered (the same applies to the bases). .

\<< "3 Arg      Version 5
1)Number
  . abcd
    \-> {#a #b #c #d }
  . or {#a #b #c #d }
  . or string with #
    & letters AZ
    (A=10 Z=35)
2)base_beg
3)base_end
" DROP -2 CF -3 CF -105 CF 1 CF 2 CF R\->I SWAP R\->I ROT DTAG DUP DUP TYPE 5 \=/ SWAP TYPE 2 \=/ AND
  IF
  THEN DUP FP 0 \=/
    IF
    THEN IP
    END R\->I ABS \->STR DUP DUP TYPE SWAP SIZE R\->I
  ELSE DUP TYPE 2 ==
    IF
    THEN "." "" SREPL DROP
    END DUP DUP TYPE SWAP SIZE R\->I
  END \-> b2 b1 n t s
  \<< n DUP "base " b1 + \->TAG SWAP TYPE 2 ==
    IF
    THEN { } 1 s
      FOR i n i i SUB NUM DUP 65 \>=
        IF
        THEN 55
        ELSE 48
        END - R\->I +
      NEXT DUP "or " SWAP 'n' STO \->TAG
    ELSE
      IF b1 36 \<=
      THEN "" 1 s
        FOR i n i GET DUP 10 \>=
          IF
          THEN 55 + 1 SF CHR
          END +
        NEXT "or " \->TAG
        IF 1 FC?
        THEN DROP
        END
      END
    END 0 1 s
    FOR i n i GET b1 s i - ^ * +
    NEXT "\->base 10" \->TAG DUP { } SWAP 1 CF
    IF b2 10 ==
    THEN DROP2
    ELSE
      WHILE DUP
      REPEAT b2 IDIV2 ROT SWAP DUP 10 \>= b2 36 \<= AND
        IF
        THEN 1 SF
        ELSE
          IF b2 10 \<=
          THEN 2 SF
          END
        END + SWAP
      END DROP REVLIST DUP SIZE 's' STO "\->base " b2 + \->TAG
      IF b1 10 ==
      THEN t 2 == 4 3 IFTE DUP 't' STO ROLLD OBJ\-> 2 8 SUB \->TAG t ROLLD t 2 / FLOOR DROPN
      END DUP 'n' STO
      IF 1 FS? 2 FS? OR
      THEN "" 1 s
        FOR i n i GET DUP 9 >
          IF
          THEN 55 + CHR
          END +
        NEXT "or " \->TAG
        IF 2 FS?
        THEN SWAP DROP DTAG OBJ\-> "\->base " b2 + \->TAG
        END
      END
    END
  \>>
\>>