Set a bit:

bitp |= (1 << pos);

Reset or clear:

bitp &= ~(1 << pos);

Toggle a bit:

bitp ^= (1 << pos);
(bitp & (~(1 << pos))) | ((~bitp) & (1 << pos)))

You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

logical and bitwise or, bit shifting, obtain bit mask, reverse bits, swap bits, bit set, reset/clear, toggle, xor operator, bitwise shifting, Operator precedence, operator precedence,

# C Programming Language (Prentice Hall Software)
# Let Us C Paperback - 2006 by Yashavant Kanetkar
# Understanding and Using C Pointers Core techniques for memory management
# Data Structures Using C and C++ Paperback - 1998
# Data Structures In C Paperback - August 11, 2008 by Noel Kalicharan