And Calculator - Bitwise AND, Truth Table, and Result
Use this and calculator to apply the bitwise AND to two numbers in binary, octal, decimal, or hex at 4, 8, 12, or 16 bits, with the truth table.
and Calculator
Results
What Is an and Calculator?
An and calculator returns the bitwise AND of two numbers by multiplying each pair of corresponding bits. Type the two operands in binary, octal, decimal, or hex, choose a bit width, and the result panel shows the AND in the same base, padded in binary, and written in hex. The result is always less than or equal to either input because AND cannot set bits that are not already set in both operands.
- • Bit masking: Keep only the bits you care about by ANDing a value with a mask such as x & 0x0F for the low 4 bits of a byte.
- • Permission and flag checks: Test whether a specific bit is set in a flag register, such as checking the READ permission bit.
- • Network and low-level programming: Combine IP octets, extract color channels from packed RGB values, and isolate status bits.
- • Boolean algebra homework and exams: Verify the truth table for two- or three-input AND expressions.
The bitwise AND is one of the four foundational bitwise operators in most programming languages, alongside OR, XOR, and NOT. It operates one bit at a time, so the result depends on the binary representation of the inputs.
If you also need OR, XOR, or NOT on the same pair of numbers, Binary Operations Calculator runs all of the bitwise operations side by side so the results are easy to compare.
How the and Calculator Works
The calculator parses the two inputs in the chosen base, masks each input to the bit width, multiplies the bits column by column, and formats the result. The 2-input AND truth table is generated from the four fixed bit pairs (00, 01, 10, 11).
- A_bit_i: The bit at position i in the binary representation of Number 1, counted from the right starting at 0.
- B_bit_i: The bit at position i in the binary representation of Number 2, counted from the right starting at 0.
- result_bit_i: The bit at position i of the AND result. Equals 1 only when both A_bit_i and B_bit_i are 1; otherwise 0.
- bitWidth: The chosen number of bits (4, 8, 12, or 16). Inputs and the result are masked to this width so the high bits are dropped.
The four bit pairs that drive the truth table are always the same: 0 AND 0 = 0, 0 AND 1 = 0, 1 AND 0 = 0, and 1 AND 1 = 1. Any longer binary number is a stack of those four cases.
Decimal 21 AND decimal 25 (8-bit)
Number 1 = 21, Number 2 = 25, base = decimal, width = 8
21 in binary is 00010101 and 25 in binary is 00011001. Aligning them: 00010101 AND 00011001 = 00010001.
AND result in decimal: 17. In binary: 00010001. In hexadecimal: 0x11.
Only bits at position 4 (16) and position 0 (1) are set in both numbers, so the result keeps those two bits. 17 = 16 + 1 confirms the bits that survived.
Hexadecimal FF AND hexadecimal 0F (8-bit)
Number 1 = FF, Number 2 = 0F, base = hex, width = 8
FF in binary is 11111111 and 0F in binary is 00001111. Aligning them: 11111111 AND 00001111 = 00001111.
AND result in decimal: 15. In binary: 00001111. In hexadecimal: 0x0F.
AND with 0F keeps only the low 4 bits of FF. This is the standard idiom for extracting the low nibble of a byte.
According to MDN Web Docs, the bitwise AND operator returns 1 in each bit position only when the corresponding bits of both operands are 1, and 0 otherwise.
According to Omni Calculator, bitwise AND is computed by aligning two binary numbers to the right and multiplying each pair of bits, so 10101 AND 11001 equals 10001 because only the leftmost and rightmost aligned pairs are 1 AND 1.
To convert the inputs or the result between binary, octal, decimal, and hex without doing the math by hand, Binary Converter accepts a value in any of those bases and prints the rest.
Key Concepts Behind the Bitwise AND
Four short ideas explain why the AND behaves the way it does and how it relates to the other tools on the site. Once these are clear, AND stops looking like a magic operator and starts looking like a column-by-column multiplication table.
Logical AND vs bitwise AND
Logical AND takes two Boolean values and returns a single Boolean. Bitwise AND applies that same true/false rule to every bit position in two binary numbers, so the result is also a binary number. The four-pair truth table is identical.
Truth table for a 2-input AND
For inputs A and B, the AND gate outputs 1 only when A = 1 and B = 1. The other three rows (00, 01, 10) all output 0. This is the same table the calculator renders on the page.
AND in programming notation
Most languages use a single ampersand for bitwise AND, written a & b, while logical AND uses a double ampersand a && b. Some languages spell the logical form as 'and' or 'AND'.
Bit masking with AND
AND with a constant that has 1s only in the positions you want to keep acts as a mask. x & 0x0F keeps the low 4 bits, x & 0x80 isolates the high bit, and x & 0 clears every bit.
The same rule extends to more than two inputs. A 3-input AND returns 1 only when all three bits at that position are 1, so a single 0 anywhere in the input collapses the entire column to 0.
When the inputs are Boolean expressions with AND, OR, and NOT, Boolean Algebra Calculator evaluates the full expression and shows the truth table for the variables.
How to Use the and Calculator
Enter the two operands, pick the base they are written in, and pick the bit width. The result panel updates in real time.
- 1 Type Number 1 and Number 2: Enter the two operands in the first row. They must use the same base. For decimal, type digits like 21 and 25. For binary, use only 0 and 1. For hex, you can also use the letters A through F.
- 2 Pick the input base: Use the Input Base dropdown to select 2 (binary), 8 (octal), 10 (decimal), or 16 (hexadecimal). Both operands are read in this base.
- 3 Pick the bit width: Use the Bit Width dropdown to select 4, 8, 12, or 16. Values that would overflow a smaller width have their high bits dropped, like a fixed-width register.
- 4 Read the AND result: The highlighted AND Result (Decimal) row shows the bitwise AND as a non-negative integer. The Binary and Hex rows show the same value padded to the bit width and prefixed with 0x for hex.
- 5 Compare against the truth table: The 2-input AND truth table below shows the four (A, B) bit pairs and their outputs. Any column in a longer binary AND follows one of those four rows.
Example: a developer wants to keep only the low 4 bits of the byte 0xAB. They type AB into Number 1 and 0F into Number 2, leave the base at Hexadecimal, the bit width at 8, and read the result: 0x0B in hex, 00001011 in binary, 11 in decimal.
When the result is in binary and you need to read it in hex without doing the nibble grouping yourself, Binary to Hexadecimal Calculator converts a binary string to its hexadecimal value in one step.
Benefits of Using This and Calculator
AND is one of the simplest operators to define, but mixing bases and bit widths by hand is the easy place to lose a bit. The calculator keeps the operands, the base, and the width consistent.
- • Bit-level result without manual alignment: The result panel shows the AND in decimal, binary, and hex at the same time, with no need to align bits on paper or reformat the result for a writeup.
- • Works in binary, octal, decimal, and hex: Type the operands in the base your problem statement uses and the result appears in that base plus binary and hex for free.
- • Bit-width masking matches real hardware: Choose 4, 8, 12, or 16 bits to mimic a fixed-width register. Values that overflow the chosen width have their high bits dropped, like AND with a width-sized mask in C, JavaScript, or Python.
- • Truth table next to the numeric result: The 2-input AND truth table is rendered on the same page, so a student or reviewer can verify the numeric answer against the four (A, B) -> output rows.
- • Reusable for masking and flag checks: The same workflow works for permission bit tests (x & 4 to check bit 2), color channel extraction (r & 0xFF), and hardware register reads.
The biggest practical win is consistency. AND behaves the same way regardless of which base the inputs are written in, and the calculator applies that rule in one pass.
When the next step is to add the masked value to another number, Binary Addition Calculator performs the binary addition with carry and returns the sum in the same base.
Factors That Affect the Result and Its Limits
The bitwise AND is fixed, but four choices about the inputs change what the result means.
Input base
The base only changes how the inputs are parsed. The bitwise AND operates on the underlying integer, so 0xFF in hex and 255 in decimal produce the same result.
Bit width
4, 8, 12, and 16 bits set the size of the result. AND of 255 and 15 in 4-bit width returns 15 because the high bits of 255 are dropped before the AND.
Sign of the inputs
The calculator treats the inputs as non-negative integers. A negative two's-complement input is out of scope; apply the two's-complement conversion first if you need signed bitwise behavior.
Invalid characters for the chosen base
A digit that is not allowed in the chosen base (such as a 2 in binary or a G in hex) fails to parse and the result falls back to 0 until the input is corrected.
- • The calculator takes exactly two operands. For three or more inputs, AND the first two and feed the result back in as Number 1 with the third value as Number 2, repeating until one value remains.
- • The inputs are read as non-negative integers, and the result is non-negative. For signed two's-complement integers, convert to the unsigned form, AND, and interpret the result as signed afterward.
When the inputs and the bit width are clear, the result is fully determined and matches what the same operation would produce in C, Java, JavaScript, or Python.
According to Wolfram MathWorld, the logical AND (also called conjunction) of two Boolean values is true only when both operands are true, which is the same rule that the bitwise AND applies one column at a time.
When the next step is to combine the AND result with another value, Binary Subtraction Calculator performs base-2 subtraction with borrow and a two's-complement mode at the same bit width.
Frequently Asked Questions
Q: What is the and calculator?
A: The and calculator returns the bitwise AND of two numbers. It accepts operands in binary, octal, decimal, or hexadecimal, applies the bit-by-bit AND at a chosen bit width, and shows the result in the same base plus binary and hex alongside the 2-input truth table.
Q: How do you compute the bitwise AND of two numbers?
A: Write both numbers in binary, align them on the right, and multiply the bits in each column. The result is 1 only when both bits are 1; otherwise the column is 0. The calculator does that for you.
Q: What is the truth table of an AND gate?
A: For two inputs A and B, the AND gate outputs 1 only when A = 1 and B = 1. The other three rows (00, 01, 10) all output 0. The page renders that 2-input truth table directly.
Q: What is the difference between bitwise AND and logical AND?
A: Logical AND takes two Boolean values and returns a single Boolean. Bitwise AND applies that same Boolean rule to every bit position in two integers, so the result is also an integer.
Q: How many inputs can an AND gate have?
A: An AND gate can have any number of inputs. The output is 1 only when every input bit at that position is 1. A single 0 input forces the output to 0 for that column.
Q: Why is the AND operation useful in programming?
A: AND is the standard way to mask bits, isolate a color channel from a packed RGB value, test whether a specific flag is set, and clear bits you do not want. The pattern x & mask is a common low-level idiom.