removed duplicate function + added some comments to header files
[smdp.git] / include / bitops.h
1 #if !defined( BITOPS_H )
2 #define BITOPS_H
3
4 /*
5  * Macros to do bit operations on integer variables.
6  *
7  * macro: SET_BIT to set bit at pos of var to 1
8  * macro: CLEAR_BIT to set bit at pos of var to 0
9  * macro: TOGGLE_BIT to toggle bit at pos of var from 1 to 0 and vice versa
10  * macro: CHECK_BIT returns > 0 if bit at pos of var is set to 1
11  *
12  * Example:
13  *      int i = 0;
14  *      i = SET_BIT(i, 2);
15  *      if(CHECK_BIT(i, 2))
16  *          printf("bit 2 is set\n");
17  *      printf("value of i is %d\n", i);
18  *
19  */
20
21 #define SET_BIT(var, pos)    ((var) |= (1<<(pos)))
22 #define CLEAR_BIT(var, pos)  ((var) &= (~(1<<(pos))))
23 #define TOGGLE_BIT(var, pos) ((var) ^= (1<<(pos)))
24 #define CHECK_BIT(var, pos)  ((var) &  (1<<(pos)))
25
26 #endif // !defined( BITOPS_H )