Re: Are these the best set of bitset macros in the world or what!?

On 09/13/10 04:17 PM, Brian wrote:
// This macro is key
#define bitn(n) (1<< n)

A common one at that.

// Define some stuff to "document" code without documenting anything
("self-documenting code")!
#define bitset8 uint8
#define bitset16 uint16
#define bitset32 uint32
#define bitset64 uint64

These can be tidied up to

typedef uint8_t bitset8;
typedef uint16_t bitset16;
typedef uint32_t bitset32;
typedef uint64_t bitset64;

// Gotta love "close to the metal"!
#define chkbit(x, n) (((x)& bitn(n)) ne 0)


#define setbit(x, n) ((x) |= bitn(n))
#define clrbit(x, n) ((x)&= ~bitn(n))
#define tglbit(x, n) ((x) ^= bitn(n))

#define chkmask(x, m) (((x)& (m)) eq m)


#define setmask(x, m) ((x) |= (m))
#define clrmask(x, m) ((x)&= (~m))
#define tglmask(x, m) ((x) ^= (m))

// some uses may require the following
#define bitn64(n) (1ui64<< n)



Aside, I use n-1 rather than n in the bitn macros, knowing that there is
potential for error there.

Do you?

Ian Collins