[erlang-questions] Interleave binaries

Bob Cowdery bob@REDACTED
Fri Aug 5 23:26:16 CEST 2011


Hi

I'm wanting to interleave two binaries.

Bin1 = <<0,1>>,
Bin2 = <<2,3>>,
<< <<A,B,C,D>> || <<A,B>> <= Bin1, <<C,D>> <= Bin2 >>.
<<0,1,2,3>>

Bin1 = <<0,1,2,3>>,
Bin2 = <<4,5,6,7>>,
<< <<A,B,C,D>> || <<A,B>> <= Bin1, <<C,D>> <= Bin2 >>.
<<0,1,4,5,0,1,6,7,2,3,4,5,2,3,6,7>>

whereas I want:
<<0,1,4,5,2,3,6,7>>

I know what it does is what the documentation says but is there a way to
get a pure interleave efficiently. Perhaps there is a filter that would
work or a way to reduce the binary after merging without stepping
through the whole thing.

Regards
Bob



More information about the erlang-questions mailing list