Too much affects.... a solution

From: Wout Mertens (Wout.Mertens@rug.ac.be)
Date: 10/31/95


Hiya all!

Here's a little gem for all you people with +32 affects on your char...
It's from the Fidonet C_ECHO newsgroup snippets....

Only rotten thing is that you can't test two bits at once any more, 
unless you're sure they're both in the same byte.
Ah well, win some, lose some...

Hope this helps...
Gekke.

/*
**  large bit array operations by Scott Dudley
*/

#include <limits.h>

#define BitOff(a,x) ((void)((a)[(x)/CHAR_BIT] &= ~(1 << ((x) % CHAR_BIT))))
#define BitOn(a,x)  ((void)((a)[(x)/CHAR_BIT] |= (1 << ((x) % CHAR_BIT))))
#define IsBit(a,x)  ((a)[(x)/CHAR_BIT] & (1 << ((x) % CHAR_BIT)))

#include <stdio.h>

main()
{
        char array[64];

        memset(array,'\0',sizeof(array));

        BitOn(array,5);
        BitOn(array,12);
        BitOn(array,500);

        if (IsBit(array,5) && IsBit(array,12) && IsBit(array,500))
                puts("These functions seemed to work!");
        else puts("Something's broken here!");
}



This archive was generated by hypermail 2b30 : 12/07/00 PST