[erlang-questions] Simple binary question

Dmitrii 'Mamut' Dimandt dmitriid@REDACTED
Tue Aug 21 12:58:15 CEST 2007


Per Gustafsson wrote:
> Dmitrii 'Mamut' Dimandt wrote:
>> Suppose I have a binary:
>>
>> 00 00 31 00 00
>>
>> This 16#31 is actually "1" in ascii.
>>
>> However, if I do a <<_Pad:2/binary, Number/integer, _Rest/binary>> or
>> <<_Pad:2/binary, Number:1/binary, _Rest/binary>> I get 16#31.
>>
>> If I do a binaty_to_list/1 or integer_to_list/1 I still get 16#31.
>>
>> How do I get "1", if it's at all possible?
>>
>> Thank you
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://www.erlang.org/mailman/listinfo/erlang-questions
>
> You'll have to do list_to_integer(binary_to_list(Number)).
>
> Per
>
Thank you, it worked! :)



More information about the erlang-questions mailing list