Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Andy Neil
08/25/12 11:18
Read: 772 times

Msg Score: +1
 +1 Good Answer/Helpful
#188167 - Setting & clearing bits
Responding to: Raghunathan's previous message
#define MASK 0x10

some_value |=  MASK;    // Set  only the '1' bits in MASK

some_value &= ~MASK;    // Clear only the '1' bits in MASK
Thus you only need one MASK definition to allow both setting & clearing the particular set of bits.

some_value |= ~MASK;    // Set   all bits except the '1' bits in MASK

some_value &=  MASK;    // Clear all bits except the '1' bits in MASK

Raghunathan said:
spare a thought that there could be novices also and for whom c-code is hobby

Some essential 'C' references for you:

List of 6 messages in thread
A simple doubt in C      Raghunathan      08/25/12 09:58      
   Clears 7 low bits but protects unknown # of high bits        Per Westermark      08/25/12 11:04      
      Pesrpective...      Raghunathan      08/25/12 21:18      
   Setting & clearing bits        Andy Neil      08/25/12 11:18      
      Concept is very clear now...      Raghunathan      08/25/12 21:08      
         Practical C Programming      Andy Peters      09/04/12 15:57      

Back to Subject List