working with binaries

Christian S chsu79@REDACTED
Tue Jul 11 10:58:51 CEST 2006


list_to_binary([A,B]) for concatenation.

As for sub binaries, I tend to use pattern matching.

1> A = <<"ABCDEFGHIJKLM">>.
<<65,66,67,68,69,70,71,72,73,74,75,76,77>>
2> <<_:5/binary,Sub:3/binary,_/binary>> = A.
<<65,66,67,68,69,70,71,72,73,74,75,76,77>>
3> Sub.
<<70,71,72>>

It would be interesting to hear comments on the pattern matching
approach. I tend to use the method to index individual bytes from
binaries too. Is it terribly inefficient or as low constant factor
O(1) as one can get?

On 7/11/06, Yani Dzhurov <Yani.Dzhurov@REDACTED> wrote:
>
>
>
>
> Hi all,
>
>
>
> Are there any more possible operations, except size, with binarites(<<…>>).
> I need such as appending binaries and getting sub-binaries.
>
> I know I can get them by first converting to lists , operating with lists
> and then convert to binaries again, but is there a way to do it straight
> with binaries?
>
>
>
> Thanx,
>
>
>
> Jani
>



More information about the erlang-questions mailing list