Non-decimal radices/Input: Difference between revisions

Added Elixir and corrected a reference place.
(Added Elixir and corrected a reference place.)
Line 6:
The solutions may assume that the base of the number in the string is known. In particular, if your language has a facility to guess the base of a number by looking at a prefix (e.g. "0x" for hexadecimal) or other distinguishing syntax as it parses it, please show that.
 
The reverse operation is in task [[CommonNon-decimal number base formattingradices/Output]]
 
For general number base conversion, see [[NumberNon-decimal base conversionradices/Convert]].
 
For general number base conversion, see [[Number base conversion]].
=={{header|Ada}}==
 
Line 257 ⟶ 258:
? __makeInt("200", 10)
# value: 200</lang>
 
=={{header|Elixir}}==
base: 2 .. 36
<lang elixir>iex(1)> String.to_integer("1000")
1000
iex(2)> String.to_integer("1000",2)
8
iex(3)> String.to_integer("1000",8)
512
iex(4)> String.to_integer("1000",16)
4096
iex(5)> String.to_integer("ffff",16)
65535</lang>
 
=={{header|Erlang}}==
Line 596 ⟶ 610:
= {String.toInt "052"} %% octal
= {String.toInt "0b101010"} %% binary</lang>
 
=={{header|PARI/GP}}==
Binary conversion is built in to PARI/GP, this script can convert from bases2-36 to bases 2-36. I've had help with this script at http:\\mersenneforums.org . The main flaw in this script I see is that it doesn't allow 36^x-1 type strings, I'll have to add that on later.
Anonymous user