Non-decimal radices/Convert: Difference between revisions

→‎{{header|Quackery}}: rewrote to match task requirements
m (syntax highlighting fixup automation)
(→‎{{header|Quackery}}: rewrote to match task requirements)
Line 3,054:
=={{header|Quackery}}==
 
Handles radices in the range 2 to 36.
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.
 
<syntaxhighlight lang="quackeryQuackery">( [ $[ ''base overput 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$ base_to_string ( n bn --> $ )
 
[ base put
say "The number 2970609818455516403037 in hexatrigesimal is "
$->n drop
2970609818455516403037 36 >base$ echo$
say "." base release ] is string_to_base ( $ n --> n )</syntaxhighlight>
 
{{out}}
 
As a dialogue in the quackery shell.
<pre>The number 2970609818455516403037 in hexatrigesimal is hexatrigesimal.</pre>
 
<pre>/O> $ "sesquipedalian" 36 string_to_base
...
 
Stack: 4846409295160778886623
 
/O> 36 base_to_string echo$ cr
...
sesquipedalian
 
Stack empty.
</pre>
 
=={{header|R}}==
1,462

edits