转换二进制字符串为十六进制,反之亦然药剂中 [英] Convert a binary string to Hexadecimal and vice-versa in Elixir

查看:193
本文介绍了转换二进制字符串为十六进制,反之亦然药剂中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你怎么一个二进制字符串转换为十六进制字符串,反之亦然在药剂?

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

有SO上关于这个话题的其他主流语言的几个职位。甚至还有一个 SO后的基准各种C#实现

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... :(

推荐答案

有是的 Base.en code16 / 2

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

您也可以指定这样的:

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

这篇关于转换二进制字符串为十六进制,反之亦然药剂中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆