bitfuncs.h
Raw
1#ifndef CUTILS_BITFUNCS_H
2#define CUTILS_BITFUNCS_H
3
4#include <stdlib.h>
5#include <cutils/common.h>
6
7#define numbits(type) (sizeof(type)*CHAR_BIT)
8#define numbytes(type) (sizeof(type))
9
10#define getbit(value, bit) (((value) >> (bit)) & 1)
11
12#define setbit(value, bit) ((value) |= ((uintmax_t)1 << (bit)))
13#define clearbit(value, bit) ((value) &= ~((uintmax_t)1 << (bit)))
14
15#define setbitc(value, bit, type) ((value) |= ((type)1 << (bit)))
16#define clearbitc(value, bit, type) ((value) &= ~((type)1 << (bit)))
17
18#endif /* CUTILS_BITFUNCS_H */
19