binary constructor

Sebastian Bello <>
Fri Feb 25 17:55:54 CET 2005


Hi Mats,

I'm not sure if this is the correct way to do it, but it works.
Try list_to_binary("123").

And to decode it 
    Binary=list_to_binary("123"),
    <<Bin:3/binary>> = Binary,
    binary_to_list(Bin).

If there's a better way to do it, I would like to know it too.
    Sebastian-

----- Original Message ----- 
From: "Mats Cronqvist" <>
To: <>
Sent: Friday, February 25, 2005 2:23 PM
Subject: binary constructor


>   so i read this in the reference manual 
> (http://www.erlang.se/doc/doc-5.4/doc/reference_manual/part_frame.html);
> 
> <<E1,...,En>>
> 
> Ei = Value |
>       Value:Size |
>       Value/TypeSpecifierList |
>       Value:Size/TypeSpecifierList
> 
> used in a binary construction, Value is an expression which should evaluate to 
> an integer, float or string. If the expression is something else than a single 
> literal or variable, it should be enclosed in parenthesis.
> 
> 
>    this leads me to believe i should be able to do this;
> 
> A = "123",
> <<A>>.
> 
>    alas, i get a badarg.
>    can somone please point out my mistake?
> 
>    mats
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20050225/d3eaa726/attachment.html>


More information about the erlang-questions mailing list