Hi All,
I am not quite clear understanding what the C macro below do:
Thanx for any detail explanation for above code.Code:#define BIT(word, i) (((word) & 1 << (i)) >> (i)) /* Pass data into BIT macro */ BIT(0x00FF, 5);
KW
Hi All,
I am not quite clear understanding what the C macro below do:
Thanx for any detail explanation for above code.Code:#define BIT(word, i) (((word) & 1 << (i)) >> (i)) /* Pass data into BIT macro */ BIT(0x00FF, 5);
KW
Given a value 'word', and a number 'i', do the following:
Shift the value of 1 'i' places to the left.
Use a bitwise AND to see if that bit is set on the value 'word'.
Take the result of that & operation, and shift it back 'i' places.
Thus:
0001000100010001
Let's say we check the 5th place.
10000
0001000100010001 & 10000
Thus, we have a "true", or a 1.
10000 >> 5 times is 1
In a nutshell, it just tests to see if a single bit is set, and it returns a "true" or "false" (a 1 or a 0). There really is no point in going through the additionall right shifts. Just test your value for zero, and if it's not zero, the value is set.
Quzah.
Hope is the first step on the road to disappointment.
Thanks! quzah.
KingogtheWorld
==================
Think globally, Act locally.