K
Krumble Bunk
Hello!
First things first (but not necessarily in that order), this is a
really great group, and has helped me understand more and more C
everytime I read the postings, so thanks for a great learning
environment!
I am having difficulty understanding this bitwise macro (i've recently
moved into working on these, using OpenSolaris source code -
magnificent learning resource btw!)
#define setbit(a, i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
#define clrbit(a, i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
#define isset(a, i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
where NBBY is defined as 8
I imagine that "a" is a 32bit int, and i is the position of the bit in
the word/int that wants to be set. I don't understand why they divide
by NBBY though? I sort of understand the rest, but if someone could
perhaps spare the time to explain the "setbit" macro, i can extrapolate
the rest for myself.
Many thanks!!
KB
First things first (but not necessarily in that order), this is a
really great group, and has helped me understand more and more C
everytime I read the postings, so thanks for a great learning
environment!
I am having difficulty understanding this bitwise macro (i've recently
moved into working on these, using OpenSolaris source code -
magnificent learning resource btw!)
#define setbit(a, i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
#define clrbit(a, i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
#define isset(a, i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
where NBBY is defined as 8
I imagine that "a" is a 32bit int, and i is the position of the bit in
the word/int that wants to be set. I don't understand why they divide
by NBBY though? I sort of understand the rest, but if someone could
perhaps spare the time to explain the "setbit" macro, i can extrapolate
the rest for myself.
Many thanks!!
KB