Bitwise Calculator (AND, OR, XOR)
- a = 12 in binary is 1100.
- b = 10 in binary is 1010.
- AND keeps a 1 only where both numbers have a 1: 1000 = 8.
- OR keeps a 1 where either number has a 1: 1110 = 14.
- XOR keeps a 1 where exactly one number has a 1: 0110 = 6.
A bitwise calculator performs bitwise operations on two integers, comparing them bit by bit. AND keeps a 1 only where both bits are 1, OR keeps a 1 where either bit is 1, and XOR keeps a 1 where exactly one bit is 1. For example, 12 (1100) and 10 (1010) give AND 8 (1000), OR 14 (1110), and XOR 6 (0110). Similarly, 25 and 19 give AND 17, OR 27, and XOR 10. This page works with non-negative integers up to 2,147,483,647 (the 32-bit range); negative numbers depend on the machine's signed representation. The calculator returns the AND, OR, and XOR results for any valid pair of integers you enter.
Bitwise logic is the accepted standard for this kind of calculation because it mirrors how processors handle integers at the hardware level, making it indispensable for low-level programming, cryptography, and digital design. The method follows directly from useful identities such as a XOR a = 0, a XOR 0 = a, and a AND b + a XOR b = a + b when there are no carries, which shows that XOR is addition without carry. Masking tricks like 255 AND 15 = 15, where AND with a mask of low 1-bits keeps only the low nibble, demonstrate the practical power of these operations. To ensure full transparency, this page displays the formula, step-by-step workings, worked examples, and sources so you can verify every result.
Worked examples
Textbook example
Primary result: 8 — 1100 AND 1010 keeps only the shared high bit. (12 · 10)
| a AND b | 8 |
| a OR b | 14 |
| a XOR b | 6 |
| a AND b (binary) | 1000 |
| a OR b (binary) | 1110 |
| a XOR b (binary) | 0110 |
Overlapping bits
Primary result: 17 — AND 17, OR 27, XOR 10. (25 · 19)
| a AND b | 17 |
| a OR b | 27 |
| a XOR b | 10 |
| a AND b (binary) | 0001 0001 |
| a OR b (binary) | 0001 1011 |
| a XOR b (binary) | 0000 1010 |
Byte masking
Primary result: 15 — AND with 15 keeps only the low nibble of 255. (255 · 15)
| a AND b | 15 |
| a OR b | 255 |
| a XOR b | 240 |
| a AND b (binary) | 0000 1111 |
| a OR b (binary) | 1111 1111 |
| a XOR b (binary) | 1111 0000 |
AND, OR and XOR, bit by bit
Bitwise operations compare two integers bit by bit, which is the core logic behind any bitwise calculator. The three operations follow simple rules that you can read as truth tables applied column by column. AND keeps a 1 only where both bits are 1, OR keeps a 1 where either bit is 1, and XOR keeps a 1 where exactly one bit is 1. In every other case, the result bit is 0.
Take the worked example of 12 (1100) and 10 (1010). Line the binary values up column by column and apply each rule down the line. AND gives 8 (1000) because only the leftmost column has a 1 in both numbers. OR gives 14 (1110) because every column has at least one 1. XOR gives 6 (0110) because the two middle columns each have exactly one 1, while the leftmost column has two 1s and the rightmost has none. A second worked example confirms the same pattern: 25 and 19 give AND 17, OR 27, and XOR 10.
These operations show up in practical programming tricks. The classic masking trick is 255 AND 15 = 15. Here, AND with a mask of low 1-bits keeps only the low nibble, discarding everything above it. Several useful identities also fall out of the bit-by-bit logic: a XOR a = 0, a XOR 0 = a, and a AND b + a XOR b = a + b when there are no carries. That last identity captures why people describe XOR as addition without carry.
This page works with non-negative integers up to 2,147,483,647, the 32-bit range. Negative numbers depend on the machine's signed representation, so results for those values can vary from system to system.
Worked examples
Bitwise operations compare two integers bit by bit: AND keeps a 1 only where both bits are 1, OR keeps a 1 where either bit is 1, and XOR keeps a 1 where exactly one bit is 1. To see how a bitwise calculator applies these rules, walk through a few verified cases in both decimal and binary.
Take 12 (1100 in binary) and 10 (1010). Align the bits and apply each operation column by column. AND keeps a 1 only where both bits are 1, so 1100 AND 1010 gives 1000, which is 8 in decimal. OR keeps a 1 where either bit is 1, so 1100 OR 1010 gives 1110, which is 14. XOR keeps a 1 where exactly one bit is 1, so 1100 XOR 1010 gives 0110, which is 6.
Now consider 25 (11001) and 19 (10011). AND yields 10001, which is 17 in decimal. OR yields 11011, which is 27. XOR yields 01010, which is 10. Each result follows directly from comparing the corresponding bits: AND requires both to be 1, OR requires at least one to be 1, and XOR requires exactly one to be 1.
A common masking trick uses AND with a mask of low 1-bits to keep only the low nibble. For example, 255 AND 15 equals 15. In binary, 255 is 11111111 and 15 is 00001111, so the AND clears every upper bit and keeps only the lower four, giving 00001111. This is the classic masking trick for isolating the lowest nibble of a byte.
Useful identities can help you check results: a XOR a equals 0, a XOR 0 equals a, and a AND b plus a XOR b equals a plus b when there are no carries — XOR is addition without carry. This page works with non-negative integers up to 2,147,483,647, the 32-bit range; negative numbers depend on the machine's signed representation.
| Expression | Decimal A | Binary A | Decimal B | Binary B | AND (decimal) | AND (binary) | OR (decimal) | OR (binary) | XOR (decimal) | XOR (binary) |
|---|---|---|---|---|---|---|---|---|---|---|
| 12 & 10 | 12 | 1100 | 10 | 1010 | 8 | 1000 | 14 | 1110 | 6 | 0110 |
| 25 & 19 | 25 | 11001 | 19 | 10011 | 17 | 10001 | 27 | 11011 | 10 | 01010 |
| 255 & 15 | 255 | 11111111 | 15 | 00001111 | 15 | 00001111 | — | — | — | — |
What programmers use bitwise operations for
Programmers reach for a bitwise calculator when they need to manipulate individual bits inside an integer rather than treat it as a plain number. Bitwise operations compare two integers bit by bit: AND keeps a 1 only where both bits are 1, OR keeps a 1 where either bit is 1, and XOR keeps a 1 where exactly one bit is 1. These three operations form the backbone of low-level programming because they map directly to simple hardware logic, making them fast and predictable across platforms.
One of the most common uses is masking — using AND to isolate specific bits while forcing the rest to zero. The classic masking trick appears when you AND a value with 15, whose binary form is 00001111. For example, 255 AND 15 equals 15, keeping only the low nibble (the lowest four bits) and discarding everything above it. Programmers use this technique to pack multiple small values into a single integer, extract fields from status registers, or test whether a particular flag is set. OR plays the opposite role: it sets bits without disturbing the others. XOR is the surgeon's tool, flipping exactly the bits that differ and leaving the rest untouched.
Permission systems rely heavily on these operations. File access rights, user roles, and device modes are often stored as individual bits within a single integer, where each bit represents a distinct permission. Checking a permission means ANDing the stored value with a mask and testing whether the result is nonzero. Granting a permission means ORing the mask in. Revoking can use XOR or a combination of AND with an inverted mask. This approach remains common in operating systems, network protocols, and embedded firmware because it is compact and efficient.
Beyond flags and permissions, bitwise operations power checksums, graphics rendering, and embedded register control. XOR is especially valuable because of its useful identities: a XOR a equals 0, a XOR 0 equals a, and a AND b plus a XOR b equals a plus b when there are no carries — XOR is addition without carry. These properties make XOR ideal for error detection, toggling pixels in graphics buffers, and swapping values without a temporary variable. The worked examples illustrate the pattern clearly: 12 (1100) and 10 (1010) give AND 8 (1000), OR 14 (1110), and XOR 6 (0110). Similarly, 25 and 19 give AND 17, OR 27, and XOR 10. This page works with non-negative integers up to 2,147,483,647 (the 32-bit range); negative numbers depend on the machine's signed representation, which is why bitwise code at the system level must account for how the hardware stores negative values.
Reading the binary patterns
When you use a bitwise calculator, reading the binary output is easier if you group the bits into chunks of four, a habit borrowed from hexadecimal notation. A single bit is hard to interpret on its own, but a group of four bits — called a nibble — maps cleanly to one hexadecimal digit, which makes spotting patterns far simpler. Two nibbles side by side form a byte, eight bits total, and most results you see will fit within one or two bytes. If the output shows 1110, you can recognize that as one nibble. If it shows 01100110, that is two nibbles, or one byte, and the leading zero simply keeps the grouping tidy.
A quick way to sanity-check a result by eye is to recall what each operation does. AND keeps a 1 only where both bits are 1, OR keeps a 1 where either bit is 1, and XOR keeps a 1 where exactly one bit is 1. Take 12 (1100) and 10 (1010) as an example. AND gives 8 (1000) because only the leftmost bit is 1 in both numbers. OR gives 14 (1110) because three of the four positions have at least one 1. XOR gives 6 (0110) because only the two middle positions differ between the two inputs. If your result has a 1 where both inputs had 0, or a 0 where both inputs had 1, something is off.
The masking trick is another pattern worth recognizing. When you compute 255 AND 15, the result is 15. Here, 255 is all 1-bits and 15 is a mask of low 1-bits, so AND keeps only the low nibble of the first operand. This is the classic way to isolate the lowest four bits of any number. Working through 25 and 19 gives AND 17, OR 27, and XOR 10. You can verify the AND result by checking that 17 in binary (10001) has a 1 only where both 25 (11001) and 19 (10011) also have a 1.
A few identities help you confirm results without re-checking every bit. The relation a XOR a = 0 tells you that XORing a number with itself always produces zero, while a XOR 0 = a means XORing with zero leaves the number unchanged. The identity a AND b + a XOR b = a + b holds when there are no carries, which is why XOR is sometimes described as addition without carry. Keep in mind that this page works with non-negative integers up to 2,147,483,647, the 32-bit range. Negative numbers depend on the machine's signed representation, so their binary patterns may not match what you expect.
FAQs
What is 12 AND 10?
The result is 8. In binary, 12 is 1100 and 10 is 1010. The AND operation compares each bit position and outputs 1 only when both bits are 1. Here, only the top bit (worth 8) is 1 in both numbers, so every other position becomes 0, giving a final result of 8.
What is the difference between AND, OR and XOR?
AND needs both bits to be 1 to output 1. OR needs at least one bit to be 1. XOR needs exactly one bit to be 1 — it is the 'one or the other but not both' operation. So AND is the strictest, OR is the most permissive, and XOR sits in between, rejecting matching pairs.
What is bitwise masking?
Bitwise masking means AND-ing a number with a mask of selected 1-bits to keep only those bits and zero out the rest. For example, 255 AND 15 = 15 isolates the low nibble. The mask 15 is 00001111 in binary, so it preserves the four lowest bits and clears everything above them.
Why does a XOR a equal 0?
When you XOR a number with itself, every bit is compared with itself. Each position has either two 0s or two 1s, so no position has exactly one 1. The XOR rule requires exactly one 1 to output 1, so it gives 0 everywhere, making the entire result 0.
Can this calculator handle negative numbers?
No. It works with non-negative integers up to 2,147,483,647. Negative results depend on the signed representation a machine uses, such as two's complement or sign-and-magnitude. Because that representation varies across systems, the calculator avoids ambiguity by limiting input to non-negative values only.
Where are bitwise operations used in real code?
Bitwise operations appear in permission and feature flags, network masks, checksums, image processing and microcontroller registers. Anywhere a program needs to manipulate individual bits efficiently, these operations provide a fast, low-level way to set, clear, toggle or test specific bits without affecting the rest of the data.