Erlang:如何将十进制转换为填充零的十六进制字符串 [英] Erlang: How to transform a decimale into a Hex string filled with zeros

查看:133
本文介绍了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:如何将十进制转换为填充零的十六进制字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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