Skip to content

Instantly share code, notes, and snippets.

@pavi2410
Created September 8, 2020 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavi2410/1ac0e7d6e3f4e2c2a10738773f38d102 to your computer and use it in GitHub Desktop.
Save pavi2410/1ac0e7d6e3f4e2c2a10738773f38d102 to your computer and use it in GitHub Desktop.
// Sets the bit at pos to 1 if 0, else keeps unchanges
void set_bit(int *bits, int pos) {
(*bits) |= (1 << pos);
}
// Clears the bit at pos to 0 if 1, else keeps unchanged
void clear_bit(int *bits, int pos) {
(*bits) &= ~(1 << pos);
}
// Returns the bit at pos
int check_bit(int *bits, int pos) {
bit = (*bits) & (1 << pos);
return bit;
}
// Toggles the bit at pos
void toggle_bit(int *bits, int pos) {
(*bits) ^= (1 << pos);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment