Created
June 13, 2015 20:53
-
-
Save tyre/64a9e2dad06d2d427bda to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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