Go Down

Topic: If statement - checking only the first 5 MSB's. (Read 1 time) 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

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131