Erlang:如何将十进制转换为填充零的十六进制字符串

编程入门 行业动态 更新时间:2024-10-28 00:20:57
本文介绍了Erlang:如何将十进制转换为填充零的十六进制字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想将42(Base 10)转换成Erlang的000002A(Base 16)...

我在网路上找到了一些指针: p>

io:format(〜8..0B〜n,[42]) - > 00000042

And

code> io:format(〜.16B〜n,[42]) - > 2A

但是我似乎无法找到如何同时做到这一点,我试过: / p>

io:format(〜8..0.16B〜n,[42])

哪个似乎是合乎逻辑的东西,但不是,这给我一个错误。

谢谢。

解决方案

io:format(〜8.16.0B〜n ,[42])。 0000002A

基本上,它是〜FPPad其中:

  • F =字段宽度
  • P = precsion
  • Pad = pad字符

请参阅 full io:format docs

I would like to transform 42 (Base 10) into 000002A (Base 16) in Erlang...

I have found some pointers on the web :

io:format("~8..0B~n", [42]) -> 00000042

And

io:format("~.16B~n", [42]) -> 2A

But I cannot seems to find how to do both at the same time, I have tried :

io:format("~8..0.16B~n", [42])

Which seemed to be the logical thing, but it is not, it gives me an error.

Thanks.

解决方案

io:format("~8.16.0B~n", [42]). 0000002A

basically, it's ~F.P.Pad where:

  • F = field width
  • P = precsion
  • Pad = pad character

see the full io:format docs

更多推荐

Erlang:如何将十进制转换为填充零的十六进制字符串

本文发布于:2023-10-27 18:35:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534199.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   字符串   如何将   Erlang   十六进制

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!