Created
April 15, 2014 19:13
-
-
Save pragdave/10761181 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 Bitmap do | |
defstruct value: 0 | |
defimpl Access do | |
use Bitwise | |
def access(%Bitmap{value: value}, bit) do | |
if (value &&& (1 <<< bit)) == 0, do: 0, else: 1 | |
end | |
end | |
end | |
fifty = %Bitmap{value: 50} | |
[5,4,3,2,1,0] |> Enum.each(fn bit -> IO.puts fifty[bit] end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment