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:04
Read: times


 
Msg Score: +1
 +1 Good Answer/Helpful
#188166 - Clears 7 low bits but protects unknown # of high bits
Responding to: ???'s previous message
~0x7f is inverting all bits.

So for an 8-bit number, you get 0x80.
For a 16-bit number, you get 0xff80.
For a 32-bit number, you get 0xffffff80.

And &= is a bit-and. It can never turn on bits, but can clear bits.

In this case, it will clear the 7 low bits.

If you knew you had a 8-bit wide port, you could have written:

P1MDIN &= 0x80;

But if the register was 16-bit wide, you had instead to write:

P1MDIN &= 0xFF80;

In short - going that extra route with ~ to invert the bits, you make sure that the & operation will handle whatever number of bits that the register happens to be wide.

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