Convert a binary string to Hexadecimal and vice-versa in Elixir

老子叫甜甜 提交于 2019-12-19 05:20:34

问题


How do you convert a binary string to a Hexadecimal String and vice-versa in Elixir?

There are a few posts on SO regarding this topic for other "main stream" languages. There's even an SO post that benchmarks various C# implementations

How do we do this in elixir?

My implementation was too ugly to share... :(


回答1:


There is Base.encode16/2:

iex(1)> Base.encode16("foo")
"666F6F"

You can also specify the case:

iex(2)> Base.encode16("foo", case: :lower)
"666f6f"


来源:https://stackoverflow.com/questions/33347909/convert-a-binary-string-to-hexadecimal-and-vice-versa-in-elixir

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!