integer to binary

Sean Hinde <>
Fri Oct 7 12:39:29 CEST 2005


This thread might help

http://forums.trapexit.org:81/phpBB/viewtopic.php?t=4660

Sean

On 7 Oct 2005, at 10:57, chandru wrote:

> Hi,
>
> I want to convert an integer to a binary without having to
> guess/figure-out how many bytes are required to fit that integer.
> There doesn't seem to be a way to do this with the bit syntax.
>
> 11> <<12345678901:40>>.
> <<2,223,220,28,53>>
>
> 12> <<12345678901:48>>.
> <<0,2,223,220,28,53>>
>
> In the example above, the integer will fit in 5 bytes but I can't
> think of a way to specify this without trial and error. Any
> suggestions? I can write a function which will figure out how many
> bytes are required but it'll be nice to have a built-in way of doing
> it.
>
> cheers
> Chandru
>




More information about the erlang-questions mailing list