[erlang-questions] Reverses Order of Bytes in Binary

Harit Himanshu harit.subscriptions@REDACTED
Sat Jan 10 20:50:18 CET 2015


Thanks a lot all, that was the only know I knew based on what I found in
documentation, but I learnt lot other ways to do it.

Plus, One thing I learnt is how to measure performance, so Thank you all
for your time and effort
+ Harit

On Sat, Jan 10, 2015 at 5:07 AM, Michael Uvarov <freeakk@REDACTED> wrote:

> 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
>>
>>
> _______________________________________________
> 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/0729af16/attachment.htm>


More information about the erlang-questions mailing list