Binary and
From Wikipedia, the free encyclopedia
|
|
This article does not cite any references or sources. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed. (June 2009) |
| It has been suggested that this article or section be merged with Bitwise operation#AND. (Discuss) |
If two conditions are combined by and, they must both be true for the compound condition to be true as well.
Likewise, two bits may be combined with and:
| x | y | x AND y |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
I.e. the result is 1, if both x and y are 1, and 0 otherwise. If 0 is equated with false, and 1 with true the bit and operation works like our logical and.
Binary and can work on binary numbers of any size, the numbers are simply anded digit by digit. For example:
| x | 10001101 |
|---|---|
| y | 01010111 |
| x AND y | 00000101 |
Only in the sixth and eighth bit did both operands have a 1 (true) value.
and is often called masking, because y can be seen as a mask which is transparent (1) in some places (x will shine through), and black (0) in others (x will be blocked).