Non-decimal radices/Input: Difference between revisions

Content added Content deleted
(Added Elixir and corrected a reference place.)
Line 6: 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 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 [[Common number base formatting]]
The reverse operation is in task [[Non-decimal radices/Output]]

For general number base conversion, see [[Non-decimal radices/Convert]].


For general number base conversion, see [[Number base conversion]].
=={{header|Ada}}==
=={{header|Ada}}==


Line 257: Line 258:
? __makeInt("200", 10)
? __makeInt("200", 10)
# value: 200</lang>
# 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}}==
=={{header|Erlang}}==
Line 596: Line 610:
= {String.toInt "052"} %% octal
= {String.toInt "052"} %% octal
= {String.toInt "0b101010"} %% binary</lang>
= {String.toInt "0b101010"} %% binary</lang>

=={{header|PARI/GP}}==
=={{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.
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.