Non-decimal radices/Convert: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) m (→{{header|11l}}) |
(Added Quackery.) |
||
Line 2,622: | Line 2,622: | ||
<pre>In [1: baseN(26, 16) |
<pre>In [1: baseN(26, 16) |
||
Out[1]: '1a'</pre> |
Out[1]: '1a'</pre> |
||
=={{header|Quackery}}== |
|||
The built-in word <code>number$</code> (included in listing) provides conversion of a number to a string in the current <code>base</code>. The valid range of bases is 2 to 36 inclusive, digits greater than 9 are represented by upper-case letters. The word <code>>base$</code> adapts <code>number$</code>to the requirements of the task by temporarily overriding the current <code>base</code> and converting the returned string from upper to lower case. |
|||
<lang Quackery>( [ $ '' over abs |
|||
[ base share /mod digit |
|||
rot join swap |
|||
dup 0 = until ] |
|||
drop |
|||
swap 0 < if |
|||
[ $ '-' swap join ] ] is number$ ( n --> $ ) |
|||
[ base put |
|||
number$ |
|||
base release |
|||
$ '' swap |
|||
witheach |
|||
[ lower join ] ] is >base$ ( n b --> $ ) |
|||
say "The number 2970609818455516403037 in hexatrigesimal is " |
|||
2970609818455516403037 36 >base$ echo$ |
|||
say "."</lang> |
|||
{{out}} |
|||
<pre>The number 2970609818455516403037 in hexatrigesimal is hexatrigesimal.</pre> |
|||
=={{header|R}}== |
=={{header|R}}== |