Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev | Author | Line No. | Line |
---|---|---|---|

1 | rm5248 | 1 | `/**` |

2 | ` * This file contains some general bit checking utilities.` |
||

3 | ` * There are three macros, which follow the same format. They are` |
||

4 | ` * CHECK_BIT, SET_BIT, and CLEAR_BIT. Each takes the first argument` |
||

5 | ` * of a variable, and the second argument is the bit to operate on.` |
||

6 | ` * This bit number is zero-based.` |
||

7 | ` *` |
||

8 | ` * Example:` |
||

9 | ` *` |
||

10 | ` * int x = 0;` |
||

11 | ` * SET_BIT( x, 0 );` |
||

12 | ` * SET_BIT( x, 2 );` |
||

13 | ` * //At this point, bits 0 and 2 are set. x is now 5` |
||

14 | ` * ` |
||

15 | ` * CLEAR_BIT( x, 0 ); //x is now 4` |
||

16 | ` *` |
||

17 | ` * if( CHECK_BIT( x, 2 ) ){ //CHECK_BIT returns non-zero if the bit is set` |
||

18 | ` * //code` |
||

19 | ` * }` |
||

20 | ` *` |
||

21 | ` */` |
||

22 | |||

23 | `#ifndef RM_UTIL_H` |
||

24 | `#define RM_UTIL_H` |
||

25 | |||

26 | `#define CHECK_BIT(number,bit) (number & (0x1 << bit))` |
||

27 | `#define SET_BIT(number, bit) (number |= (0x1 << bit))` |
||

28 | `#define CLEAR_BIT(number, bit) (number &= (~(0x1 << bit)))` |
||

29 | |||

30 | `#endif` |