aboutsummaryrefslogtreecommitdiff
path: root/include/bitset.h
blob: 4945d5b1411a17cb36d948b5bb0051e44d2a637f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef MLIB_BITSET_H
#define MLIB_BITSET_H

#include <limits.h>

#define _MLIB_BITSLOT(x) ((x) / CHAR_BIT)
#define _MLIB_BITMASK(x) (1 << ((x) % CHAR_BIT))

#define bitset(name, n) unsigned char name[(n + CHAR_BIT - 1) / CHAR_BIT]

#define CLRBIT(bs, x)  ((bs)[_MLIB_BITSLOT(x)] &= ~_MLIB_BITMASK(x))
#define SETBIT(bs, x)  ((bs)[_MLIB_BITSLOT(x)] |= _MLIB_BITMASK(x))
#define TOGLBIT(bs, x) ((bs)[_MLIB_BITSLOT(x)] ^= _MLIB_BITMASK(x))
#define TESTBIT(bs, x) ((bool)((bs)[_MLIB_BITSLOT(x)] & _MLIB_BITMASK(x)))

#endif /* !MLIB_BITSET_H */