Created
March 10, 2017 00:43
-
-
Save ninovsnino/ea2304fa5052a8758235d89eac83c035 to your computer and use it in GitHub Desktop.
bit set and clear example in c
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
#include "stdio.h" | |
#define ID_A 0x01 | |
#define ID_B 0x02 | |
int main() { | |
unsigned char type; | |
unsigned short result; | |
printf("size of unsigned char = %x\n", sizeof(unsigned char) ); | |
printf("size of unsigned short = %x\n", sizeof(unsigned short) ); | |
result = ID_B; | |
type = ID_A; | |
if ( type == ID_A ) | |
{ | |
result |= ID_A; | |
} | |
printf("set result = %x\n", result ); | |
if ( result & ID_A ) | |
{ | |
result &= ~(ID_A); | |
} | |
printf("clear result = %x\n", result ); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment