Skip to content

Instantly share code, notes, and snippets.

@ninovsnino
Created March 10, 2017 00:43
Show Gist options
  • Save ninovsnino/ea2304fa5052a8758235d89eac83c035 to your computer and use it in GitHub Desktop.
Save ninovsnino/ea2304fa5052a8758235d89eac83c035 to your computer and use it in GitHub Desktop.
bit set and clear example in c
#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