Search code examples
cexpressionboolean-logicxormsp430

Is P1DIR |= (BIT0 | BIT6); and P1DIR |= BIT0 + BIT6; identical expressions?


Yeah. I would like to know this. programming on my new msp430g2553 and both seems to work. The first one is from an online tutorial and the second one is what I had already put in my code and seems to work...

Are they identical?

UPDATE

BIT0 = 0x01 BIT6 = 0x04


Solution

  • In this case, yes they are the same. The same can't be said for an expression where you have more than 2 'bits' or where the 2 'bits' are the same.

    Assuming BIT0 = 00000001 and BIT6 = 01000000

    Then BIT0 | BIT6 = 01000001 and BIT0 + BIT6 = 01000001

    But if we were using the same 'bits' twice ..

    BIT0 | BIT0 = 00000001
    

    BUT

    BIT0 + BIT0 = 00000010