Bitwise Calculator (AND, OR, XOR)
Bitwise AND, OR and XOR of two integers aligned in binary. AND outputs 1 only where both bits are 1: 1 AND 1 = 1, and every other combination gives 0. Example: with first integer 12, …, the result is 12 AND 10 = 8; 12 OR 10 = 14.
Last updated · By S. Dilshan · Runs in your browser, nothing is uploaded
Step-by-Step Solution
How do you use the Bitwise Calculator (AND, OR, XOR)?
Enter two non-negative integers up to 2,147,483,647. The calculator converts both to binary, pads them to the same width so the bits line up, and applies AND, OR and XOR to each pair of bits. It shows each result in binary and in decimal, so you can see both the pattern and the number.
This is useful for checking bit masks, flag combinations and permission values. For other bit tasks, such as converting numbers between bases, use the converters on this site.
What formula does the Bitwise Calculator (AND, OR, XOR) use?
AND outputs 1 only where both bits are 1: 1 AND 1 = 1, and every other combination gives 0. OR outputs 1 where at least one bit is 1. XOR, short for exclusive or, outputs 1 where the bits differ and 0 where they match. The operators work independently on each bit position, without any carrying between positions.
In many languages they are written &, | and ^. A few useful identities: x AND 0 is 0, x OR 0 is x, x XOR x is 0, and XOR-ing a value with the same number twice returns the original, which is the basis of simple toggling and swapping tricks.
Worked example: 12 and 10
In binary, 12 is 1100 and 10 is 1010. AND compares each column: 1 and 1 give 1, 1 and 0 give 0, 0 and 1 give 0, and 0 and 0 give 0, so 12 AND 10 = 1000 = 8. OR gives 1110 = 14. XOR gives 0110 = 6, because only the middle two bits differ. As a check, XOR-ing the result 6 with 10 returns 12, confirming the reversible property of XOR.
Bitwise operations in practice
AND is used to mask bits, for instance extracting the low four bits of a byte with AND 15. OR sets bits, combining independent flags such as read, write and execute permissions into one number. XOR toggles bits and is used in checksums, simple encryption and finding the one unpaired number in a list.
Network engineers apply AND between an IP address and a subnet mask to find the network address. Graphics code packs colour channels into one integer using shifts and masks. Because bitwise operations are among the fastest a processor can do, they also appear in performance-sensitive code.
What are the most common mistakes with the Bitwise Calculator (AND, OR, XOR)?
- Confusing bitwise AND (&) with the logical AND (&&) used in conditions.
- Forgetting operator precedence, which is why masks are usually wrapped in brackets.
- Ignoring the width of the data type, so results overflow or become negative in signed types.
- Expecting XOR to behave like addition. It is addition without carry.
What Is the Tested Example for the Default Values?
This example is computed by the same code that powers the calculator above, so you can compare it with your own numbers or a textbook answer.
| Input: First integer | 12 |
|---|---|
| Input: Second integer | 10 |
| 12 AND 10 | 8 |
| 12 OR 10 | 14 |
| 12 XOR 10 | 6 |
Where Can You Verify These Formulas?
The definitions and formulas on this page follow standard references. Check them against these sources:
Built and maintained by S. Dilshan. Found a mistake? Email [email protected] with the page address.
Frequently Asked Questions
What does bitwise AND do?
It outputs 1 only in positions where both inputs have a 1.
What is XOR used for?
XOR outputs 1 when the bits differ, which is handy for toggling flags and basic parity checks.
What range does this calculator support?
Non-negative integers up to 2,147,483,647 (31 bits), matching signed 32-bit integers.