BPLightContraption
 All Classes Namespaces Files Functions Variables Macros Pages
bits.h
Go to the documentation of this file.
1 /*! \file
2  * \brief Macros to make bit manipulation easier
3  * \author Benjamin Pritchard (ben@bennyp.org)
4  * \copyright 2013 Benjamin Pritchard. Released under the MIT License
5  */
6 
7 #ifndef BIT_H
8 #define BIT_H
9 
10 /*! Get bit m in register p */
11 #define bit_get(p,m) ((p) & (0x01 << m))
12 
13 /*! Set bit m in register p */
14 #define bit_set(p,m) ((p) |= (0x01 << m))
15 
16 /*! Clear bit m in register p */
17 #define bit_clear(p,m) ((p) &= ~(0x01 << m))
18 
19 /*! Flip or toggle bit m in register p */
20 #define bit_flip(p,m) ((p) ^= (0x01 << m))
21 
22 /*! Convert a bit position to a bit */
23 #define BIT(x) (0x01 << (x))
24 
25 #endif