Tech & Digital
Bitwise Calculator (AND, OR, XOR, NOT, Shifts)
Computers store whole numbers as sequences of bits, ones and zeros, and bitwise operations act directly on those bits. They are essential tools in programming, electronics and networking: they set and clear flags, pack several values into one number, mask IP addresses, compute checksums and make some arithmetic very fast. The AND operation produces a 1 only where both inputs have a 1, so it is used to test or keep selected bits with a mask. OR produces a 1 where either input has a 1, which is used to switch bits on. Exclusive OR, XOR, produces a 1 where the bits differ, so it toggles bits and has the useful property that applying the same XOR twice restores the original value. NOT flips every bit. Shifts move all the bits left or right: shifting left by n places multiplies by 2 to the power n, and a logical right shift divides by 2 to the power n, discarding the remainder. This calculator works with unsigned 32-bit integers, the size used by bitwise operators in many programming languages, including JavaScript. You can type numbers in decimal, in binary with the prefix 0b, or in hexadecimal with the prefix 0x, so 12, 0b1100 and 0xC all mean the same value. The results show the answer in decimal, hexadecimal and binary, the same bits interpreted as a signed 32-bit integer, both inputs written in binary aligned for easy comparison, and the number of bits set. Signed results matter because computers usually store negative numbers in two’s complement form, in which the NOT of a number equals minus the number minus one.
How to use this calculator
- Enter the first number in decimal, 0b binary or 0x hexadecimal.
- Choose the operation.
- Enter the second number, or the shift distance for shifts.
- Read the result in decimal, hexadecimal and binary.
- Compare the binary forms of the inputs to see which bits changed.
Masks and flags
Programs often store several on/off options in one number, giving each a bit. To test whether option 4 is set, AND the value with 0b100; to switch it on, OR with 0b100; to toggle it, XOR with 0b100.
Network engineers use AND with a subnet mask to find the network address of an IP address, for example 192.168.1.37 AND 255.255.255.0 gives 192.168.1.0.
Two's complement
Most computers represent negative integers in two's complement: the highest bit indicates the sign, and −1 is stored as all ones.
That is why NOT 0 gives 4,294,967,295 as an unsigned value but −1 as a signed one: the bits are the same, only their interpretation differs.
Formula & method
AND: 1 where both bits are 1; OR: 1 where either is 1; XOR: 1 where they differNOT flips every bit of a 32-bit valueLeft shift by n multiplies by 2ⁿ; logical right shift divides by 2ⁿ, discarding the remainderCalculations use unsigned 32-bit integers, as in many programming languagesAND: a & b. OR: a | b. XOR: a ^ b. NOT: ~a. Left shift: a << n = a × 2ⁿ (mod 2³²). Logical right shift: a >>> n = ⌊a ÷ 2ⁿ⌋. Results shown as unsigned 32-bit values.
Worked example
12 AND 10
- 12 = 1100 and 10 = 1010 in binary.
- AND keeps bits set in both: 1000.
- 1000 in binary is 8 (0x8).
Answer: 12 & 10 = 8.
Frequently asked questions
What is XOR used for?
Exclusive OR is used to toggle bits, compare values, compute checksums and parity, and in simple ciphers, because applying the same XOR twice restores the original value.
Why does NOT give a large number?
NOT flips all 32 bits, so small numbers become large unsigned values; in signed arithmetic the same bits represent −(a + 1).
How do I enter hexadecimal?
Type 0x before the digits, for example 0xFF for 255.
What is the difference between >> and >>>?
An arithmetic right shift (>>) keeps the sign bit for negative numbers, while a logical shift (>>>), used here, fills with zeros.
Why are results limited to 32 bits?
Many languages apply bitwise operators to 32-bit integers, so results wrap around beyond that size.
What does bits set mean?
The number of 1 bits in the result, also called the population count or Hamming weight.