[erlang-questions] Reverses Order of Bytes in Binary

Michael Uvarov freeakk@REDACTED
Sat Jan 10 14:07:01 CET 2015


there's another  way:

reverse(Bin) when is_binary(Bin) ->

    S = bit_size(Bin),

    <<V:S/integer-little>> = Bin,

    <<V:S/integer-big>>.




On January 10, 2015 12:24:54 PM CET, "Сергей Прохоров" <seriy.pr@REDACTED> wrote:
>Probably this one will be more effective
>
>reverse(Bin) ->
>    reverse(Bin, byte_size(Bin)).
>
>reverse(_, 0) -> <<>>;
>reverse(Bin, Pos) ->
>    <<(binary:at(Bin, Pos - 1)), (reverse(Bin, Pos - 1))/binary >>.
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>erlang-questions mailing list
>erlang-questions@REDACTED
>http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150110/9500fef4/attachment.htm>


More information about the erlang-questions mailing list