[erlang-questions] Reverses Order of Bytes in Binary

Ivan Uemlianin ivan@REDACTED
Sat Jan 10 12:30:55 CET 2015


Remember lists:reverse/1 is implemented in C & does some non-erlangy things (IIRC) so should be jolly fast & efficient.  Unless binary_to_list/1 is v bad the OP's version is the best so far (imho).

Best wishes

Ivan


--
festina lente


> On 10 Jan 2015, at 11:24, Сергей Прохоров <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



More information about the erlang-questions mailing list