Created
June 26, 2018 17:14
-
-
Save KelsonBall/121fd27053983ac15783d3e01f67364a to your computer and use it in GitHub Desktop.
mask.cpp
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
bool HasBit(int mask, int index) | |
{ | |
return (mask & (1 << index)) != 0; | |
} | |
int SetBit(int mask, int index) | |
{ | |
return mask | (1 << index); | |
} | |
int UnsetBit(int mask, int index) | |
{ | |
return mask ^ (1 << index); | |
} | |
int cities = 0; | |
cities = SetBit(cities, 1); | |
cities | |
2 | |
cities = UnsetBit(cities, 1); | |
cities | |
0 | |
HasBit(SetBit(cities, 3), 3) | |
true | |
HasBit(SetBit(cities, 3), 2) | |
false | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment