Created
October 4, 2016 11:59
-
-
Save andersonfernandes/e4ac8e2c859b3671193bb874c2919111 to your computer and use it in GitHub Desktop.
Set of functions to manipulate bit in C language
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
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