parent
cd9d974a91
commit
c594c2aa9a
@ -0,0 +1,8 @@ |
|||||||
|
#pragma once |
||||||
|
|
||||||
|
#include <stdint.h> |
||||||
|
#include <stdlib.h> |
||||||
|
|
||||||
|
int is_bit_set(uint8_t *set, size_t n); |
||||||
|
void set_bit(uint8_t *set, size_t n); |
||||||
|
void clear_bit(uint8_t *set, size_t n); |
@ -0,0 +1,32 @@ |
|||||||
|
#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; |
||||||
|
} |
Loading…
Reference in new issue