Non-decimal radices/Convert: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
(→‎{{header|Quackery}}: rewrote to match task requirements)
Line 3,054: Line 3,054:
=={{header|Quackery}}==
=={{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="quackery">( [ $ '' over abs
<syntaxhighlight lang="Quackery"> [ base put
[ base share /mod digit
rot join swap
dup 0 = until ]
drop
swap 0 < if
[ $ '-' swap join ] ] is number$ ( n --> $ )

[ base put
number$
number$
base release
base release
$ '' swap
$ "" swap
witheach
witheach
[ lower join ] ] is >base$ ( n b --> $ )
[ lower join ] ] is base_to_string ( n n --> $ )


[ base put
say "The number 2970609818455516403037 in hexatrigesimal is "
$->n drop
2970609818455516403037 36 >base$ echo$
say "."</syntaxhighlight>
base release ] is string_to_base ( $ n --> n )</syntaxhighlight>


{{out}}
{{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}}==
=={{header|R}}==