Pages: 1 [2]   Go Down
Author Topic: If statement - checking only the first 5 MSB's.  (Read 584 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Edison Member
*
Karma: 32
Posts: 1382
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

'&' 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.
Logged

UK
Offline Offline
God Member
*****
Karma: 1
Posts: 530
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Pages: 1 [2]   Go Up
Jump to: