Skip to content

Instantly share code, notes, and snippets.

@tyre
Created June 13, 2015 20:53
Show Gist options
  • Save tyre/64a9e2dad06d2d427bda to your computer and use it in GitHub Desktop.
Save tyre/64a9e2dad06d2d427bda to your computer and use it in GitHub Desktop.
defmodule BitReader do
def puts_bits(bits) do
bit_string = accumulate_bits(bits)
|> Enum.join(", ")
IO.puts "<<#{bit_string}>>"
end
defp accumulate_bits(bits) do
accumulate_bits(bits, [])
end
defp accumulate_bits(<<>>, bits) do
Enum.reverse bits
end
defp accumulate_bits(<<bit::integer-size(1)-unit(1), rest::bits>>, acc) do
accumulate_bits(rest, [inspect(bit) | acc])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment