According to Wikipedia: A bitwise AND takes two equal-length binary representations and performs the logical AND operation on each pair of the corresponding bits, which is equivalent to multiplying them. Thus, if both bits in the compared position are 1, the bit in the resulting binary representation is 1 (1 × 1 = 1); otherwise, the result is 0 (1 × 0 = 0 and 0 × 0 = 0).
So, let's break this down into simpler terms:
Using a binary representation of 4 bits, let us present:
0101 (decimal 5)
0011 (decimal 3)
= 0001 (decimal 1)
5 AND 3 equals 1
So, what is happening here?
The AND compares 5 and 3's bits (as binary) if they equal a 1 or 0 in the length of AND'ed bits. You can see 5 (0101) and 3 (0011) have a far right bit that is the same to the other number, that being 1 (0101, 0011).
If it is the same in any of the bits, the AND operation will equal 1, otherwise 0. If both the decimal numbers are the same, it will equal whatever the numbers are.
Just something quick I wanted to write up after finally understanding what an AND operation is. Thank goodness for Wikipedia.
So, let's break this down into simpler terms:
Using a binary representation of 4 bits, let us present:
0101 (decimal 5)
0011 (decimal 3)
= 0001 (decimal 1)
5 AND 3 equals 1
So, what is happening here?
The AND compares 5 and 3's bits (as binary) if they equal a 1 or 0 in the length of AND'ed bits. You can see 5 (0101) and 3 (0011) have a far right bit that is the same to the other number, that being 1 (0101, 0011).
If it is the same in any of the bits, the AND operation will equal 1, otherwise 0. If both the decimal numbers are the same, it will equal whatever the numbers are.
Just something quick I wanted to write up after finally understanding what an AND operation is. Thank goodness for Wikipedia.