Re: Are these the best set of bitset macros in the world or what!?
- From: Ian Collins <ian-news@xxxxxxxxxxx>
- Date: Mon, 13 Sep 2010 16:34:54 +1200
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)
ne?
#define setbit(x, n) ((x) |= bitn(n))
#define clrbit(x, n) ((x)&= ~bitn(n))
#define tglbit(x, n) ((x) ^= bitn(n))
// WINDOW_THICK_BORDER|WINDOW_MINMAXBUTTONS anyone?
//
#define chkmask(x, m) (((x)& (m)) eq m)
eq?
#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)
Eh?
**********
Aside, I use n-1 rather than n in the bitn macros, knowing that there is
potential for error there.
Do you?
--
Ian Collins
.
- Follow-Ups:
- References:
- Prev by Date: Are these the best set of bitset macros in the world or what!?
- Next by Date: Re: Are these the best set of bitset macros in the world or what!?
- Previous by thread: Are these the best set of bitset macros in the world or what!?
- Next by thread: Re: Are these the best set of bitset macros in the world or what!?
- Index(es):
Relevant Pages
|