Skip to content

Instantly share code, notes, and snippets.

@jweinst1
Created March 14, 2025 23:52
Show Gist options
  • Save jweinst1/50f248267b2955a99ca8ad9bd2c2d524 to your computer and use it in GitHub Desktop.
Save jweinst1/50f248267b2955a99ca8ad9bd2c2d524 to your computer and use it in GitHub Desktop.
find the unset or set bits of a number in C++
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