Last active
August 29, 2015 13:59
-
-
Save pragdave/10761501 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 | |
end | |
defimpl Access, for: Bitmap do | |
use Bitwise | |
def access(%Bitmap{value: value}, bit) do | |
if (value &&& (1 <<< bit)) == 0, do: 0, else: 1 | |
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