Binary Bitwise AND Calculator
Calculate bitwise AND operations on binary numbers. Visualize bit-by-bit AND logic with binary, decimal, hex, and octal output.
About
The bitwise AND operation compares each bit of two operands and produces 1 only when both corresponding bits equal 1. This is the foundational gate in digital logic design. Misapplying AND masks in firmware or network subnet calculations leads to silent data corruption or routing failures that surface hours after deployment. This calculator accepts binary strings up to 32 bits, applies the AND operation per the IEEE standard binary representation, and returns results in binary, decimal, hexadecimal, and octal. It assumes unsigned integer representation. Inputs exceeding the selected bit width are truncated from the most significant bit side.
Bitwise AND is used in subnet masking (e.g., applying mask M to IP address A via A & M), permission flag extraction, register-level hardware control, and graphics pixel channel isolation. A common error is confusing logical AND (∧) with bitwise AND (&). Logical AND evaluates truth of entire expressions. Bitwise AND operates on each bit independently. This tool visualizes every bit position to eliminate that confusion.
Formulas
The bitwise AND operation on two n-bit unsigned integers A and B is defined as:
For each bit position i from 0 to n − 1:
Where Ri = 1 if and only if both Ai = 1 and Bi = 1. The decimal value of a binary number is computed as:
Where bi is the bit value at position i (counting from the least significant bit). Hexadecimal conversion groups bits into 4-bit nibbles from the right. Octal conversion groups bits into 3-bit groups from the right.
Key algebraic properties of bitwise AND:
Reference Data
| Bit A | Bit B | A AND B | Gate Symbol | Boolean Expression |
|---|---|---|---|---|
| 0 | 0 | 0 | & | A ⋅ B = 0 |
| 0 | 1 | 0 | & | A ⋅ B = 0 |
| 1 | 0 | 0 | & | A ⋅ B = 0 |
| 1 | 1 | 1 | & | A ⋅ B = 1 |
| Common AND Mask | Binary (8-bit) | Decimal | Hex | Purpose |
|---|---|---|---|---|
| Low nibble | 00001111 | 15 | 0x0F | Extract lower 4 bits |
| High nibble | 11110000 | 240 | 0xF0 | Extract upper 4 bits |
| Even test | 00000001 | 1 | 0x01 | Check if number is odd |
| Byte mask | 11111111 | 255 | 0xFF | Isolate lowest byte |
| Alignment (4) | 11111100 | 252 | 0xFC | Round down to multiple of 4 |
| Clear bit 3 | 11110111 | 247 | 0xF7 | Force bit 3 to 0 |
| Subnet /24 | 11111111 | 255 | 0xFF | Each octet of 255.255.255.0 |
| Subnet /16 | 11111111 | 255 | 0xFF | Each octet of 255.255.0.0 |
| RGB Red channel | 11111111 00000000 00000000 | 16711680 | 0xFF0000 | Extract red from 24-bit color |
| Permission read | 00000100 | 4 | 0x04 | Unix read permission flag |
| Permission write | 00000010 | 2 | 0x02 | Unix write permission flag |
| Permission exec | 00000001 | 1 | 0x01 | Unix execute permission flag |
| Power-of-2 test | n & (n − 1) = 0 | True if n is power of 2 | ||
| Sign bit (32-bit) | 10000000 00000000 00000000 00000000 | 2147483648 | 0x80000000 | Extract sign of signed int |
Frequently Asked Questions
&&) evaluates two boolean expressions and returns TRUE or FALSE. It uses short-circuit evaluation: if the first operand is false, the second is never evaluated. Bitwise AND (&) operates on every bit of two integer operands independently. For example, 6 (110) & 3 (011) = 2 (010). Logical AND on the same values: both are truthy, so the result is TRUE. Confusing the two in C or Java causes subtle bugs that compile without warnings.>>> 0) to force unsigned interpretation. Inputs exceeding 32 bits are not supported because JavaScript's native & operator truncates to 32 bits.