一些方便的按位操作符宏定义,在通信中运用十分方便:
#ifndef BIT_TEST
#define BIT_TEST(a, b) ( 0 != ((a) & (b)))
#endif
#ifndef BIT_SET
#define BIT_SET(a, b) ((a) |= (b))
#endif
#ifndef BIT_RESET
#define BIT_RESET(a, b) ((a) &= ~(b))
#endif
#ifndef BIT_MATCH
#define BIT_MATCH(a,b) (( (a) & (b) ) == (b))
#endif
#ifndef BIT_COMPARE
#define BIT_COMPARE(a,b,c) (( (a) & (b) ) == (c))
#endif