erlang md5 16进制字符串

搜索到的访问量最高是这个: http://blog.csdn.net/zhangxinrun/article/details/7741373

思路: 把16个byte, 每个byte变成16进制不就行了么? 但是需要补0, 例如 0x7 ==> 0x07.

我不禁想 设计erlang的人那么蠢么? 类似 %02x 的也没有么?


看看官方文档果然有:


The general format of a control sequence is ~F.P.PadModC. The character C determines the type of control sequence to be used, F and P are optional numeric arguments. If FP, or Pad is *, the next argument in Data is used as the numeric value of F or P.

F is the field width of the printed argument. A negative value means that the argument will be left justified within the field, otherwise it will be right justified. If no field width is specified, the required print width will be used. If the field width specified is too small, then the whole field will be filled with * characters.

P is the precision of the printed argument. A default value is used if no precision is specified. The interpretation of precision depends on the control sequences. Unless otherwise specified, the argument within is used to determine print width.

Pad is the padding character. This is the character used to pad the printed representation of the argument so that it conforms to the specified field width and precision. Only one padding character can be specified and, whenever applicable, it is used for both the field width and precision. The default padding character is ' ' (space).

Mod is the control sequence modifier. It is either a single character (currently only 't', for unicode translation, is supported) that changes the interpretation of Data.


几行代码搞定:

Sig = erlang:md5("123").

binary_to_list(iolist_to_binary([io_lib:format("~2.16.0b", [S]) || S <- binary_to_list(Sig)])).
"202cb962ac59075b964b07152d234b70"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值