You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
520 B
32 lines
520 B
#include <bitset.h>
|
|
#include <macros.h>
|
|
|
|
int is_bit_set(uint8_t *set, size_t n)
|
|
{
|
|
uint8_t *word, mask;
|
|
|
|
word = set + n / BIT_SIZE(*set);
|
|
mask = (1 << (n % BIT_SIZE(*set)));
|
|
|
|
return (*word & mask) ? 1 : 0;
|
|
}
|
|
|
|
void set_bit(uint8_t *set, size_t n)
|
|
{
|
|
uint8_t *word, mask;
|
|
|
|
word = set + n / BIT_SIZE(*set);
|
|
mask = (1 << (n % BIT_SIZE(*set)));
|
|
|
|
*word |= mask;
|
|
}
|
|
|
|
void clear_bit(uint8_t *set, size_t n)
|
|
{
|
|
uint8_t *word, mask;
|
|
|
|
word = set + n / BIT_SIZE(*set);
|
|
mask = (1 << (n % BIT_SIZE(*set)));
|
|
|
|
*word &= ~mask;
|
|
}
|
|
|