Non-decimal radices/Convert: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: updated REXX program for larger bases. -- ~~~~) |
|||
Line 1,178: | Line 1,178: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
Instead of writing two seperate routines, only one was written to handle both tasks. |
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> |
<lang rexx> |
||
/*REXX program converts numbers from one base to another, from 2 ──> |
/*REXX program converts numbers from one base to another, from 2 ──> 90.*/ |
||
/*┌────────────────────────────────────────────────────────────────────┐ |
/*┌────────────────────────────────────────────────────────────────────┐ |
||
Line 1,189: | Line 1,190: | ||
│ │ |
│ │ |
||
│ toBase or inBase can be a comma (,) which causes the default │ |
│ toBase or inBase can be a comma (,) which causes the default │ |
||
└─┐ of 10 to be used. The limits of both are: 2 ──> |
└─┐ of 10 to be used. The limits of both are: 2 ──> 90. ┌─┘ |
||
└────────────────────────────────────────────────────────────────────┘*/ |
└────────────────────────────────────────────────────────────────────┘*/ |
||
Line 1,195: | Line 1,196: | ||
@abcU=@abc; upper @abcU /*go whole hog and extend 'em. */ |
@abcU=@abc; upper @abcU /*go whole hog and extend 'em. */ |
||
@@@=0123456789||@abc||@abcU /*prefix 'em with numeric digits.*/ |
@@@=0123456789||@abc||@abcU /*prefix 'em with numeric digits.*/ |
||
@@@=@@@'<>[]{}()?~!@#$%^&*_+-=|\/;:~' /*add some special chars as well.*/ |
|||
⚫ | |||
/*spec. chars should be viewable.*/ |
|||
⚫ | |||
maxB=length(@@@) /*max base (radix) supported here*/ |
maxB=length(@@@) /*max base (radix) supported here*/ |
||
parse arg x toB inB . /*get a number, toBase, inBase */ |
parse arg x toB inB . /*get a number, toBase, inBase */ |
||
if toB=='' | toB==' |
if toB=='' | toB==',' then toB=10 /*if skipped, assume default (10)*/ |
||
if inB=='' | inB==' |
if inB=='' | inB==',' then inB=10 /* " " " " " */ |
||
if inB<2 | inb>maxB then call erb 'inBase',inB /*bad boy inBase.*/ |
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.*/ |
if toB<2 | tob>maxB then call erb 'toBase',toB /*bad boy toBase.*/ |
||
Line 1,223: | Line 1,226: | ||
say x "(base" inB')' center('is',20) y "(base" toB')' /*show & tell.*/ |
say x "(base" inB')' center('is',20) y "(base" toB')' /*show & tell.*/ |
||
exit |
exit |
||
/*──────────────────────────────────error subroutines───────────────────*/ |
/*──────────────────────────────────error subroutines───────────────────*/ |