>> the objective of the program is to wait until the input at port3 of the micro controller is 0000 00100 in binary
Not quite. This implies you want to know the entire value of that port (each and every bit), and would be tested with: while(P3 != 0x04)
>> But i don't see the point to the masking?
Because this program is only interested in a single bit on P3 - bit 2 specifically. The AND clears the rest of the bits, and the result is thereby determined by the value of bit 2.
Code:
Example 1: Bit 2 is high:
P3 xxxx x1xx
MASK 0000 0100
---------
Result: 0000 0100 = true
Exampe 2: Bit 2 is low:
P3 xxxx x0xx
MASK 0000 0100
---------
Result: 0000 0000 = false