您的位置:首页 > 其它

erlang md5 16进制字符串

2015-12-04 16:22 190 查看
搜索到的访问量最高是这个: 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 F, P,
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"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: