-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbits.c
37 lines (31 loc) · 889 Bytes
/
bits.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "bits.h"
const unsigned long BITS_IN_WORD = 8 * sizeof(WORD);
void setBit(WORD* bitVec, unsigned long bitNo)
{
int wordNo = bitNo / BITS_IN_WORD;
int normBitNo = bitNo % BITS_IN_WORD;
*(bitVec + wordNo) = *(bitVec + wordNo) | wordMask(normBitNo, TRUE);
}
void unSetBit(WORD* bitVec, unsigned long bitNo)
{
int wordNo = bitNo / BITS_IN_WORD;
int normBitNo = bitNo % BITS_IN_WORD;
*(bitVec + wordNo) = *(bitVec + wordNo) & wordMask(normBitNo, FALSE);
}
int wordMask(int bitNo, BOOL setBit)
{
WORD mask;
if(setBit){
mask = ( 1 << (BITS_IN_WORD - 1) );
return mask >> bitNo;
}
else{
return ~wordMask(bitNo, TRUE);
}
}
BOOL bitSet(WORD* bitVec, unsigned long bitNo)
{
int wordNo = bitNo / BITS_IN_WORD;
int normBitNo = bitNo % BITS_IN_WORD;
return *(bitVec + wordNo) & wordMask(normBitNo, TRUE);
}