You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A simple module for hexadecimal encoding / decoding in Elixir.
Note: name change from hex to hexate
Now that Elixir includes integration with Hex.pm, the library has been
renamed hexate to avoid namespace clashes.
This was manifesting itself with intermittent failures when running test
suites. If you experience this, update your deps!
If you really must use the old version, it's on the branch pre-rename-to-hexate.
Adding to your mix.exs
defpdepsdo[{:hexate,">= 0.6.0"}]end
Usage
Encode to string (binary):
# From a stringiex>Hexate.encode("This is a test.")"54686973206973206120746573742e"# From a char-listiex>Hexate.encode('This is a test.')"54686973206973206120746573742e"iex>Hexate.encode(123456)"1e240"iex>Hexate.encode(15,4)"000f"iex>Hexate.encode(15.0,2)"0f"iex>Hexate.encode(15.0)"f"
Decode to string (binary):
# From a hex stringiex>Hexate.decode("54686973206973206120746573742e")"This is a test."# From a hex char-listiex>Hexate.decode('54686973206973206120746573742e')"This is a test."
Encode to hex char-list:
# From a unicode char-listiex>Hexate.encode_to_list('This is a test.')'54686973206973206120746573742e'# From a unicode stringiex>Hexate.encode_to_list("This is a test.")'54686973206973206120746573742e'# From an integeriex>Hexate.encode_to_list(123456)'1e240'
Decode to unicode char-list:
# From a hex char-listiex>Hexate.decode_to_list('54686973206973206120746573742e')'This is a test.'# From a hex stringiex>Hexate.decode_to_list("54686973206973206120746573742e")'This is a test.'
Convert hex to integer:
# From hex char-listiex>Hexate.to_integer('54686973206973206120746573742e')438270661302729020147902120434299950# From hex stringiex>Hexate.to_integer("54686973206973206120746573742e")438270661302729020147902120434299950