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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/25/12 17:18
Read: times


 
Msg Score: +1
 +1 Good Answer/Helpful
#188167 - Setting & clearing bits
Responding to: ???'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.

Further,
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: http://blog.antronics.co.uk/2010/12/12



List of 6 messages in thread
TopicAuthorDate
A simple doubt in C            01/01/70 00:00      
   Clears 7 low bits but protects unknown # of high bits            01/01/70 00:00      
      Pesrpective...            01/01/70 00:00      
   Setting & clearing bits            01/01/70 00:00      
      Concept is very clear now...            01/01/70 00:00      
         Practical C Programming            01/01/70 00:00      

Back to Subject List