This is my function, when I call my_conv(“2312144”, 10, 10), it gives me “bad argument” error
my_conv(S, Start, End) ->
Res = <<Start:8, End:8, S:1024>>.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A string cannot be used inside a binary expression without conversion. You need to convert the string to a binary by using
list_to_binary(S).I would recommend the following expression:
(Note here that
list_to_binary/1actually accepts a deep IO list and not just a pure string).If you intend to pad your binary to 1024 bytes (or 1040 including your newlines) you can do so afterwards: