The last comparison is a two part sequence. The first part is what is called a mask and the second part is the comparison.
(array[3] & 0xf0) == 0xe0
Remember that this check of the 4th byte of the signature wants to make sure that the first 4 bits are 1110. Also, the second 4 bytes can be anything. So, to make this check easier, a mask is employed. The &
operator is used to do a bit by bit AND between array[3] and 0xF0. Since F
is 1111 in binary, it will perform an AND with the first 4 bits. Anything that is ANDed with 1 will return that value, so if the first 4 bits are e, or 1110, it will result in e.
Next, the last 4 bytes are 0000, and anything ANDed with 0 is 0. This means that the result of the AND will be 0.
Combine all that and it means that it will pass the first 4 bits through while passing only 0 for the last 4 bits. The result can be compared to 0xE0 to verify that the 4th byte is between 0xe0 and 0xEF.
Does that make sense yet? For more info, google masks in c.
If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)