P1DIR = BIT0; // got rid of OR assignment "|="
P1OUT &= BIT0; // got rid of "~"
P1IE = BIT3; // got rid of OR assignment "|="
Now, why does this do the exactly the same thing as the original code?
Well, to be honest, rather than answer your question it might be better to ask you one in return: under what conditions would those changes result in no change in behaviour? An understanding of the bitwise operators is, as has been pointed out, essential to the sort of register manipulations you'll need to be doing when you work with a microcontroller. Since you seem to understand already what the various bitwise and assignment operators do, it shouldn't be too tricky to reason about the differences your changes made
BIT0 = 0x0001 = 0000 0001
BIT3 = 0x0008 = 0000 1000
Original:
P1DIR |= BIT0; //I'm assuming since all pins are set on input on default, P1DIR will be 0000 0000
//P1DIR |= BIT0 will equal P1DIR = 0000 0000 | 0000 0001 which equals 0000 0001
P1OUT &= ~BIT0; //Since BIT0 is set to output, I'm assuming P1OUT = 0000 0001
//P1OUT &= ~BIT0 equals P1OUT = 0000 0001 & 1111 1110 which equals 0000 0000
P1IE |= BIT3; //*I am not sure what P1IE value is at the beginning but I'm assuming it would be
//either 0000 0000 or 0000 1000
My Editted Version:
P1DIR = BIT0; // got rid of OR assignment "|="
P1OUT &= BIT0; // got rid of "~"
P1IE = BIT3; // got rid of OR assignment "|="
Which also means:
P1DIR = 0000 0001
P1OUT = P1OUT & 0000 0001 //Does P1OUT == 0000 0001? If so then the final P1OUT is 0000 0001
P1IE = 0000 1000
Please do correct me if I am wrong! As always, thank you.