bit mask
Back to dictionary
Bit masks are used to separate binary numbers into two parts: the part that matters, and the part that doesn't matter.

For example, say we have the binary number b000111 and want to know the values of the third and fourth binar digit quickly and easily. To accomplish this, we will use a bitwise AND operation.

We AND our binary number with b001100. We choose b001100 because we are interested in retaining the 3rd and 4th digits. We keep our desired digits as 1, and 0 for the rest. When these two values are ANDed, we will lose all other digits' values because we do not care about them. But for the digits we do care about, their value will determine whether a 1 or a 0 is placed in the result of the operation for their specific digits.

b000111 AND b001100 becomes b000100. We know that since a 1 is in the 3rd digit, that the third digit of our original number was a 1. Since there is a 0 in the 4th digit of the result, we know that there was a 0 in our original 4th digit.


Find more about bit mask in these tutorials:

Copyright 2006 © LC3Help.com v1.4.7