Skip to content

Instantly share code, notes, and snippets.

@mingshun
Created April 1, 2014 08:24
Show Gist options
  • Save mingshun/9910068 to your computer and use it in GitHub Desktop.
Save mingshun/9910068 to your computer and use it in GitHub Desktop.
Exercise 5 of Chapter 7, Programming Erlang 2nd Eidition
reverse_bits_in_binary(<<X/binary>>) ->
reverse_bits(X, <<>>).
reverse_bits(<<B1:1, B2:1, B3:1, B4:1, B5:1, B6:1, B7:1, B8:1, R/binary>>, T) ->
reverse_bits(R, <<B8:1, B7:1, B6:1, B5:1, B4:1, B3:1, B2:1, B1:1, T/binary>>);
reverse_bits(<<>>, T) ->
T.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment