Bitwise AND Calculator
Apply a fixed-width bitwise operation to two signed values, inspect every bit, and export the current calculation as a validated Excel workbook.
Inputs
Sets the signed one's-complement word width.
Whole number from 2 through 32; used only when Binary representation is Other.
Changing the datatype converts valid entered values instead of changing only their labels.
AND is the demonstration operation; OR and XOR use the same fixed-width bit model.
Binary digits only, with an optional leading sign.
Binary digits only, with an optional leading sign.
Results
Result (decimal)
17
Exact signed value after applying AND to the 8-bit patterns.
Result (binary)
00010001
Result (octal)
21
Number 1 binary
00010101
Number 2 binary
00011001
Set bits
2
Aligned operation
00010101
AND 00011001
────────
00010001
Bit-by-bit detail
| Bit position | Number 1 bit | Number 2 bit | Operation | Result bit |
|---|---|---|---|---|
| 7 | 0 | 0 | 0 AND 0 | 0 |
| 6 | 0 | 0 | 0 AND 0 | 0 |
| 5 | 0 | 0 | 0 AND 0 | 0 |
| 4 | 1 | 1 | 1 AND 1 | 1 |
| 3 | 0 | 1 | 0 AND 1 | 0 |
| 2 | 1 | 0 | 1 AND 0 | 0 |
| 1 | 0 | 0 | 0 AND 0 | 0 |
| 0 | 1 | 1 | 1 AND 1 | 1 |
How to use this Bitwise AND Calculator
What this calculator does
This calculator applies a bitwise operation to two integers after representing them with a fixed number of bits. Its startup example uses the AND operation, 8-bit one's-complement representation, and binary inputs. For each bit position, AND returns 1 only when the corresponding bit in both operands is 1. The same interface can also evaluate OR and XOR because the reference workflow exposes those bitwise choices alongside AND. The result is an exact identity for the selected finite-width representation; it is not a probability, estimate, or recommendation. The calculator does not model floating-point values, arbitrary-precision integers, hardware overflow beyond the selected word, or programming-language-specific coercion rules.
When to use it
Use it to check a binary exercise, verify a mask before implementing low-level code, inspect how two signed words combine bit by bit, or compare the same operands in binary, octal, and decimal notation. It is also useful when teaching logic gates because the detail table makes each local truth-table decision visible instead of showing only the final number.
How to calculate
- The calculator opens with a complete demonstration: Binary representation is 8-bit, Datatype is Binary, Bitwise operation is AND, Number 1 is 10101, and Number 2 is 11001. The first result and a validated example XLSX are ready immediately.
- Choose Binary representation. The preset choices are 4, 8, 12, and 16 bits. Select Other to expose Custom bit width, which accepts a whole number from 2 to 32.
- Choose Datatype: Binary, Octal, or Decimal. When you switch the datatype while both entries are valid, the calculator converts the existing values so their numerical meaning is preserved.
- Choose Bitwise operation. AND keeps a bit only when both input bits are 1; OR keeps it when either is 1; XOR keeps it when the two bits differ.
- Replace Number 1 and Number 2. Results, the aligned operation, and the bit table update live. Use Download Excel to export exactly the current validated state. Reset clears the demonstration data rather than restoring it; after Reset, Download Excel is disabled until both required numbers form a complete valid state again.
Input guide
Binary representation is required and determines the fixed word width. Presets are 4, 8, 12, and 16 bits; Other delegates the width to Custom bit width. In this calculator, signed values use one's-complement encoding, so an n-bit word supports magnitudes from 0 through 2n – 1 – 1 in either sign. A common mistake is entering a value that fits as an unsigned word but not in the selected signed range. For example, 127 is valid at 8 bits, while 128 is not.
Custom bit width is required only when Binary representation is Other. Enter a base-10 integer from 2 through 32, such as 20. Fractions, signs, grouping separators, and scientific notation are rejected. Increasing the width preserves more leading sign information and can make larger signed magnitudes valid; decreasing it may invalidate an existing operand.
Datatype is required and controls the notation used for Number 1 and Number 2. Binary accepts only 0 and 1, Octal accepts digits 0 through 7, and Decimal accepts digits 0 through 9. Each format allows one optional leading plus or minus sign, with no grouping commas, spaces inside the number, prefixes such as 0b or 0o, or scientific notation. For example, decimal 21 is binary 10101 and octal 25. A datatype change converts a currently valid entry instead of reinterpreting its existing characters in the new base.
Bitwise operation is required. AND is the primary mode and is usually used for masking: a 0 in either operand clears that bit. OR sets any bit present in either word, and XOR sets bits that differ. The operation changes the result pattern but never changes the two encoded operands.
Number 1 and Number 2 are required signed integers written in the selected Datatype. For the startup 8-bit binary state, 10101 and 11001 mean +21 and +25. Negative input uses a leading minus sign, such as -101 for – 5; the calculator then creates the fixed-width one's-complement pattern internally. Entering -0 is rejected because one's complement has a distinct negative-zero bit pattern and sign-text -0 is ambiguous as an input value.
Output guide
The summary pills show Operation, Word width, Input base, and Result ones. Operation mirrors the selected bitwise rule; Word width is the active number of bits; Input base is the selected notation; and Result ones counts 1 bits in the final word. The main Result (decimal) is the signed one's-complement interpretation of the result pattern. Result (binary) shows the complete word with leading zeros preserved, while Result (octal) shows the same signed numerical result in base 8. Number 1 binary and Number 2 binary show the exact encoded operands used by the operation, which is especially important for negative values. Set bits repeats the exact count of 1s in the result word.
The Bit-by-bit detail table is an exact decomposition, not an estimate. Bit position counts from the least significant bit at position 0 upward. Number 1 bit and Number 2 bit are the encoded input bits at that position. Operation shows the local expression, such as 1 AND 0. Result bit is the resulting 0 or 1. Reading the Result bit column from the highest position to position 0 reproduces Result (binary) exactly.
Worked example
With the startup values, 10101 is padded to 00010101 and 11001 is padded to 00011001. AND compares each aligned pair. Only positions 4 and 0 contain 1 in both words, so the result is 00010001. That binary word equals 16 + 1 = 17 in decimal and 21 in octal, with 2 set bits. Those are the same first-open values shown in the result cards, detail table, and exported workbook.
Learn more
For the underlying programming concept, MDN's bitwise AND operator reference explains how corresponding bits are paired and ANDed. Python's language reference also documents binary bitwise operations and their operator precedence. Programming languages may define integer width and signed representation differently from this calculator's explicit finite one's-complement model, so use the calculator's displayed word width and encoded binary operands as the authoritative state for each calculation.
How the finite-width model works
For a positive value, the calculator stores the ordinary base-2 magnitude and pads it on the left to the selected width. For a negative value, it first represents the positive magnitude in that width and then flips every bit, which is one's-complement encoding. The selected operation is performed on those encoded words. To interpret a result whose most significant bit is 1, the calculator flips the result bits again and applies a negative sign to the recovered magnitude. An all-ones word is the special negative-zero pattern; the interface labels that case as – 0 so it is not confused with the all-zero positive-zero pattern.
Fixed width matters because bitwise operators act on patterns, not on abstract decimal notation. The same signed magnitude can therefore produce different leading bits when the word width changes, and those leading bits can affect OR or XOR results. The bit table is the safest way to diagnose such differences: it exposes every encoded input bit and every local operation without introducing a chart that would imply a quantitative scale where none exists.