What does it mean to mask bits lower and higher?

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In laymans term, what does bit masking mean/do when it comes to LCD display?

I have searched online but its mostly written in a technical format.

 

lcd &= 0x0F;     //Masking lower bit

lcd |= ((x & 0x0F)<<4);     //Masking lower bit and send to display

 

What does the above mean?

 

Thanks for you help

Last Edited: Thu. Dec 7, 2017 - 08:40 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In both of these, the lower 4-bits are left unchanged and the upper bits are set to 0 i.e. masked.

The result will be that the  lower 4-bits of the value in x will be shifted left 4 bits and OR'd into the variable lcd

while the lower 4-bits of the variable lcd will contain whatever they had before both of these instructions were executed.

unit16_t lcd = 0x12A5;   // Start with some initial values

uint16_t x = 0x3469;

 

lcd &= 0x0F;   // After this lcd contains 0x0005  (The "12A" has been masked off)

lcd |= ((x & 0x0F) << 4);    // Now lcd contains 0x0095 (use only the "9" from the variable x

 

Edit: clarification of description...

David (aka frog_jr)

Last Edited: Thu. Dec 7, 2017 - 08:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Take a look here too:

 

http://www.avrfreaks.net/forum/t...

 

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks guys for clarifying it