[erlang-questions] Reverses Order of Bytes in Binary

Ivan Uemlianin <>
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, Сергей Прохоров <> 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
> 
> http://erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list