Skip to content

Instantly share code, notes, and snippets.

@andersonfernandes
Created October 4, 2016 11:59
Show Gist options
  • Save andersonfernandes/e4ac8e2c859b3671193bb874c2919111 to your computer and use it in GitHub Desktop.
Save andersonfernandes/e4ac8e2c859b3671193bb874c2919111 to your computer and use it in GitHub Desktop.
Set of functions to manipulate bit in C language
int is_bit_i_set(unsigned char c, int i) {
unsigned char mask = 1 << i;
return mask & c;
}
void set_bit(unsigned char *c, int i) {
*c |= 1 << i;
}
void clear_byte(unsigned char *byte) {
int i;
for(i = 7; i >= 0; --i) {
*byte &= ~(1 << i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment