Non-decimal radices/Convert: Difference between revisions

m
→‎{{header|REXX}}: updated REXX program for larger bases. -- ~~~~
m (→‎{{header|REXX}}: updated REXX program for larger bases. -- ~~~~)
Line 1,178:
=={{header|REXX}}==
Instead of writing two seperate routines, only one was written to handle both tasks.
<br><br>This routine was ripped out from a bigger version of mine that allowed any number as input, including decimal (or whatever base) fractions.
<lang rexx>
/*REXX program converts numbers from one base to another, from 2 ──> 6290.*/
 
/*┌────────────────────────────────────────────────────────────────────┐
Line 1,189 ⟶ 1,190:
│ │
│ toBase or inBase can be a comma (,) which causes the default │
└─┐ of 10 to be used. The limits of both are: 2 ──> 6290. ┌─┘
└────────────────────────────────────────────────────────────────────┘*/
 
Line 1,195 ⟶ 1,196:
@abcU=@abc; upper @abcU /*go whole hog and extend 'em. */
@@@=0123456789||@abc||@abcU /*prefix 'em with numeric digits.*/
@@@=@@@'<>[]{}()?~!@#$%^&*_+-=|\/;:~' /*add some special chars as well.*/
numeric digits 1000 /*what the hey, support biggies. */
/*spec. chars should be viewable.*/
numeric digits 1000 /*what the hey, support biggies. gihugeics*/
maxB=length(@@@) /*max base (radix) supported here*/
parse arg x toB inB . /*get a number, toBase, inBase */
if toB=='' | toB=='.,' then toB=10 /*if skipped, assume default (10)*/
if inB=='' | inB=='.,' then inB=10 /* " " " " " */
if inB<2 | inb>maxB then call erb 'inBase',inB /*bad boy inBase.*/
if toB<2 | tob>maxB then call erb 'toBase',toB /*bad boy toBase.*/
Line 1,223 ⟶ 1,226:
say x "(base" inB')' center('is',20) y "(base" toB')' /*show & tell.*/
exit
 
 
/*──────────────────────────────────error subroutines───────────────────*/