本文介绍了Erlang:如何将十进制转换为填充零的十六进制字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将42(Base 10)转换成Erlang的000002A(Base 16)...
我在网路上找到了一些指针: p>
io:format(〜8..0B〜n,[42]) - > 00000042And
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]) -> 00000042And
io:format("~.16B~n", [42]) -> 2ABut 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:如何将十进制转换为填充零的十六进制字符串
发布评论