cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
EXTRACT_BIT
EXTRACT_BIT
Sep 15, 2010 at 2:32pm UTC
abdallahijazi
(27)
Hello everybody,
could anyone kindly explain to me how does this line of code work step by step?
# define EXTRACT_BIT(n, i) ((n&(1<<i))?1:0)
Sincerely
Sep 15, 2010 at 2:45pm UTC
kbw
(9488)
(1<<i) left shifts one by i places.
(n&(1<<i)) performs a logical AND on n and the result of the above. That is, it pics out the (i+1)th bit.
?1:0 return one (true) if the (i+1)th bit is set or zero (false) if it isn't.
Topic archived. No new replies allowed.