AVR GCC Bit Manipulation Macros

Posted on 2008-07-27 in misc

These are some macros i originally found on avrfreaks for bit manipulation. I have posted them here in case they are useful to anyone.

1
2
3
4
5
6
7
#define bit_get(p,m) ((p) & (m))
#define bit_set(p,m) ((p) |= (m))
#define bit_clear(p,m) ((p) &= \~(m))
#define bit_flip(p,m) ((p) \^= (m))
#define bit_write(c,p,m) (c ? bit_set(p,m) : bit_clear(p,m))
#define BIT(x) (0x01 << (x))
#define LONGBIT(x) ((unsigned long)0x00000001 << (x))