Go Down

Topic: If statement - checking only the first 5 MSB's. (Read 785 times) previous topic - next topic


'&' is the bitwise and operator. It compares each bit in each operand and outputs a result according to the following truth table:

Inputs    Output
0  0            0
0  1            0
1  0            0
1  1            1

So '&' only outputs a 1 if both inputs are 1. This lets us create a "mask"
B11111000 & ident_reg_contents will return the value of the corresponding bit in ident_reg-contents when the mask is 1 and return 0 where the mask is 0. Since we do not care about the last 3 bits, setting them to zero will allow us to use a constant to compare.


Ah of course, the same as manipulating data direction registers with bitwise operations for example. Not too sure why I didn't spot that.

Thank you!

Go Up