Converting hex to bytes

What would be the functional equivalent of Python’s bytes.fromhex() in Elixir?

I found an answer from StackOverflow:


Excerpt:

Hex to binary:

Base.decode16!("0001FEFF")
=> <<0, 1, 254, 255>>

Binary to hex:

Base.encode16(<<0, 1, 255, 255>>)
=> "0001FFFF"

Base.encode16(<<0x66, 0x6F, 0x6F>>) # equivalent to "foo"
=> "666F6F"

Base.encode16("foo")
=> "666F6F"
1 Like