这是我的功能,当我调用my_conv("2312144",10,10)时,它给了我"错误的参数"错误
my_conv(S, Start, End) ->
Res = <<Start:8, End:8, S:1024>>.
Run Code Online (Sandbox Code Playgroud)
如果没有转换,则不能在二进制表达式内使用字符串.您需要使用将字符串转换为二进制文件list_to_binary(S).
我建议使用以下表达式:
my_conv(S, Start, End) ->
list_to_binary(<<Start:8, End:8>>, S]).
Run Code Online (Sandbox Code Playgroud)
(注意这里list_to_binary/1实际上接受深度IO列表而不仅仅是纯字符串).
如果您打算将二进制文件填充到1024字节(或1040包括您的换行符),则可以在以后执行此操作:
my_conv(S, Start, End) ->
pad(1040, list_to_binary(<<Start:8, End:8>>, S])).
pad(Width, Binary) ->
case Width = byte_size(Binary) of
N when N =< 0 -> Binary;
N -> <<Binary/binary, 0:(N*8)>>
end.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
519 次 |
| 最近记录: |