fork download
  1. #include <stdio.h>
  2. #define SET_BIT(x, n) ( (x) |= (1<< (n)) )
  3. #define CLR_BIT(x, n) ( (x) &= (~(1<< (n))))
  4. #define CHK_BIT(x, n) ( ((x) & (1<< (n)))!=0 )
  5. #define FLIP_BIT(x, n) ( (x) ^= (1<< (n)) )
  6.  
  7. int main(void) {
  8. static int a=0x12345678;
  9. SET_BIT(a, 3);
  10. printf("SET_BIT:a=0x%8x\n",a);
  11. CLR_BIT(a, 3);
  12. printf("CLR_BIT:a=0x%8x\n",a);
  13. CHK_BIT(a, 3);
  14. printf("CHK_BIT:a=0x%8x\n",a);
  15. FLIP_BIT(a, 3);
  16. printf("FLIP_BIT:a=0x%8x\n",a);
  17. return 0;
  18. }
Success #stdin #stdout 0s 2168KB
stdin
Standard input is empty
stdout
SET_BIT:a=0x12345678
CLR_BIT:a=0x12345670
CHK_BIT:a=0x12345670
FLIP_BIT:a=0x12345678