Performing a Bitwise AND Operation
Introduction to Bitwise AND
Operation
Performing a bitwise AND
operation involves comparing two binary numbers bit by bit and applying the AND
logic to each pair of corresponding bits. In the context of an IP address and subnet mask, this is used to determine the network address.
Here’s a step-by-step guide on how to perform a bitwise AND
operation:
Understanding the AND
Logics
The AND
operation follows a simple rule:
- If both bits are 1, the result is 1.
- If either bit is 0, the result is 0.
Example
Bitwise AND between 11100000
and 00100001
- Write Down the Binary Numbers:
Subnet mask: 11100000
IP address: 00100001
- Align them vertically for ease of comparison.
11100000 (Subnet mask)
00100001 (IP address)
- Compare Each Bit and Apply
AND
Logic:
Start from the leftmost bit and compare it down the column.
1 AND 0 = 0
1 AND 0 = 0
1 AND 1 = 1
0 AND 0 = 0
0 AND 0 = 0
0 AND 0 = 0
0 AND 1 = 0
0 AND 1 = 0
- Write Down the Result:
After performing the AND operation on each pair of bits, you get the result:
00100000
Explanation
In the example above, for each pair of bits, we apply the AND
logic. For instance, in the first column, we have 1
(from the subnet mask) AND 0
(from the IP address), which results in 0
.
We do this for each pair of bits across the two binary numbers. The resulting binary number 00100000
is the outcome of the bitwise AND operation.
The resulting binary number 00100000
is the outcome of the bitwise AND
operation, which correctly identifies the network address part of the IP address when using a /27
subnet mask.