About the AND Calculator
A bitwise AND lines two numbers up column by column and writes a 1 only where both columns already hold a 1. Everything else collapses to 0, which is why AND is the operator reached for whenever bits need to be masked away rather than added together. Paste operand A on the left, operand B in the second pane, and the answer appears with a bit layout showing each operand above the result.
Values may be typed as plain decimal, or prefixed with 0x, 0b or 0o when you would rather stay in hex, binary or octal. Auto detect reads those prefixes; pinning the input base instead forces every operand to be read the same way, which is handy when you paste a column of unprefixed hex. Extra lines in either pane are treated as further operands and folded left to right, so three subnet masks can be intersected in one pass.
Bit width controls the size of the word. On Auto the smallest of 8, 16, 32 or 64 bits that holds every operand is chosen, so small teaching examples stay readable instead of drowning in leading zeros. Pinning 32-bit matches what a C int or a JavaScript operator would do. The signed line underneath reads the same result as a two’s complement integer. To flip bits instead of masking them, open the XOR Calculator, and for the shift operators use the older Bitwise Calculator.
How to use
- Type or paste the first value into the Operand A pane.
- Put the second value in the Operand B pane, using a prefix such as
0x2Fif it is not decimal. - Pick a Bit width if you need the answer padded to a fixed word size.
- Read the bit layout to see which columns held a 1 in both operands.
Common questions
- Why does 12 AND 10 give 8?
- Written as 1100 and 1010, only the eight column has a 1 in both numbers. Every other column loses because at least one operand holds a 0 there.
- Can I AND more than two numbers?
- Yes. Put extra values on separate lines in either pane and they are folded from left to right, exactly as chained ampersands would behave.
- How do I mask off the low byte of a value?
- AND it with 0xFF00 for a 16-bit word, or with 0xFFFFFF00 for 32 bits. The zero columns in the mask clear the bits you want gone.
- What does the signed line mean?
- It reinterprets the same bit pattern as a two’s complement integer of the chosen width, so 0xFF at 8-bit shows as -1.