Created
March 14, 2025 23:52
-
-
Save jweinst1/50f248267b2955a99ca8ad9bd2c2d524 to your computer and use it in GitHub Desktop.
find the unset or set bits of a number in C++
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
size_t find_unset_bit(size_t num) { | |
return ~num & (num + 1); | |
} | |
size_t find_first_set_bit(size_t num) { | |
return num & -num; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment