Created
September 8, 2020 12:14
-
-
Save pavi2410/1ac0e7d6e3f4e2c2a10738773f38d102 to your computer and use it in GitHub Desktop.
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
// 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