Converting Hex to String

I didn’t find a way to convert a value String “0x056bc75e2d63100002” to 100000000000000000002 Integer. Any clue ?

iex(2)> input = "0x056bc75e2d63100002"
"0x056bc75e2d63100002"
iex(3)> "0x" <> hex = input
"0x056bc75e2d63100002"
iex(4)> Integer.parse(hex, 16)
{100000000000000000002, ""}
3 Likes

Sure, I just forgot to remove the “0x” on the front of the string hex value. Thanks for remember

If you are sure that parsing will success, you can also use String.to_integer/2. It will raise an ArgumentError if it can’t parse the input.