Syntax help ....

Can someone please explain (teach) the following syntax…

  PORTD |= (1 << SR_OE);                      // temporarily disable the SR outputs
{{ some code here to update the shift register data }}
  PORTD |=  (1 << SR_LE);                     // set latch pin LOW
  PORTD &= ~(1 << SR_LE);                     // set latch pin HIGH - SR outputs now have new data
  PORTD &= ~(1 << SR_OE);                     // re-enable the SR outputs

I’m confused with the |, &. and ~

i have to look it up myself when i need it but there is a great lesson on stack overflow which explains it all extensively, check the first answer.

short:

// Setting a bit
number |= 1UL << n;

// Clearing a bit
number &= ~(1UL << n);

// Toggling a bit
number ^= 1UL << n;

// Checking a bit
bit = (number >> n) & 1U;

You can refer to the language reference:
&= (compound bitwise and)

~ (bitwise not)

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.