[erlang-questions] Simple binary question

Raimo Niskanen <>
Tue Aug 21 11:57:29 CEST 2007


You have got "1".

Erlang does not have strings, but a list of integers
can be regarded as a string. The shell pretty-prints
a list of integers that corresponds to printable
ascii characters as a string:

> [16#31].
"1"

> 16#31 = 49 = $1.
49

Where $1 is the integer corresponding to the ascii value
for the character `1'.

> [16#31] = [49] = [$1].
"1"



On Tue, Aug 21, 2007 at 11:21:39AM +0300, 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
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list