[erlang-questions] Simple binary question

Per Gustafsson per.gustafsson@REDACTED
Tue Aug 21 10:51:58 CEST 2007


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



More information about the erlang-questions mailing list