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
9#define bitstring(type, value) _bitstring(numbits(type), (type)(value))
10/* FIXME: fix out of range calls (bitstring(unsigned char, 256)) */
11char* _bitstring(size_t size, uintmax_t value);
12
13#define getbit(type, value, bit) (((value) & (((type)1 << (bit)))) >> (bit))
14#define setbit(type, value, bit) ((value) |= ((type)1 << (bit)))
15#define clearbit(type, value, bit) ((value) &= (type)~((type)1 << (bit)))
16
17#endif /* CUTILS_BITFUNCS_H */
18