Search code examples
cbinarysignals

What is if (c >> a & 1) does mean?


I'm trying to understand what is this condition mean.

Does it mean after shifting the value it will be equal to 1?

I mean does it mean --> if (c >> a is 1)


Note: c >> a & 1 same as (c >> a) & 1.


Solution

  • Bitwise AND operate on bits, so the possibilities are :

    1101 & 0001 => 0001
    
    0001 & 0001 => 0001
    
    1010 & 0001 => 0000
    
    0000 & 0001 => 0000
    

    Now, on C, anything that's not a zero is treated as true, so the statement means "if after shifting the least significant bit is 1", or perhaps "if after shifting the value is odd" if you're dealing with odd-even operation.