summaryrefslogtreecommitdiff
path: root/reference/C/CONTRIB/SNIP/bitarray.c
blob: 3f09401dcee3d94e19acff1d6ddd5813ad30201d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
char set[(BITCOUNT + 7) / 8];

int getbit(char *set, int number)
{
        set += number / 8;
        return (*set & (1 << (number % 8))) != 0;       /* 0 or 1       */
}

int setbit(char *set, int number, int value)
{
        set += number / 8;
        if (value)
                *set |= 1 << (number % 8);              /* set bit      */
        else    *set &= ~(1 << (number % 8));           /* clear bit    */
}