Non-decimal radices/Convert: Difference between revisions

Content added Content deleted
(Added 11l)
Line 17: Line 17:
The programs may be limited by the word size or other such constraint of a given language. There is no need to do error checking for negatives, bases less than 2, or inappropriate digits.
The programs may be limited by the word size or other such constraint of a given language. There is no need to do error checking for negatives, bases less than 2, or inappropriate digits.
<br><br>
<br><br>

=={{header|11l}}==
Converting from string to number:
<lang 11l>print(Int(‘1A’, 16)) // returns the integer 26</lang>

Converting from number to string:
{{trans|Python}}
<lang 11l>-V digits = Array(‘0’..‘9’).join(‘’)‘’Array(‘A’..‘Z’).join(‘’)

F base_n(=num, b)
I num == 0
R ‘0’
V result = ‘’
L num != 0
(num, V d) = divmod(num, b)
result ‘’= digits[d]
R reversed(result)

print(base_n(26, 16))</lang>

{{out}}
<pre>
1A
</pre>


=={{header|ACL2}}==
=={{header|ACL2}}==