Created
July 27, 2019 19:12
-
-
Save rugyoga/49b31fa761f6bb7dc688a5148e98e465 to your computer and use it in GitHub Desktop.
Bitmask operators
This file contains 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
def get?(bitmask, offset) | |
(bitmask >> offset) & 1 == 1 | |
end | |
def set!(bitmask, offset) | |
(1 << offset) | bitmask | |
end | |
def clear!(bitmask, offset) | |
~(1 << offset) & bitmask | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment