Bitwise Calculator
Work out AND, OR, XOR, NOT and bit shifts on two numbers. Enter decimal, hex or binary at 8, 16, 32 or 64 bits and see every bit line up, with the result in hex, decimal and binary.
How to Use
- Pick the operation: AND, OR, XOR, their inverted forms, NOT, or a shift.
- Choose the width, 8 to 64 bits; it sets how NOT and shifts behave and how negative numbers are stored.
- Enter A and B in decimal, hex (0x…) or binary (0b…). For a shift, B is the number of places.
- Read the result in hex, unsigned and signed decimal, and binary. The drawing lines up every bit.
- Click any readout to copy it.
Worked Example
12 and 10, three ways. 12 is 1100 and 10 is 1010. Line them up and work column by column. AND keeps a 1 where both are 1: 1000 = 8. OR keeps a 1 where either is 1: 1110 = 14. XOR keeps a 1 where they differ: 0110 = 6. Note that AND + XOR = OR here, 8 + 6 = 14, because AND counts the shared bits and XOR the rest.
Finding a network address. 192.168.1.130 with a /26 mask (255.255.255.192) is 0xC0A80182 AND 0xFFFFFFC0. Only the last byte changes: 0x82 = 1000 0010 AND 1100 0000 = 1000 0000 = 0x80, so the network is 192.168.1.128.
The common mistake: ^ is not a power. In C, Java, JavaScript and Python, 2 ^ 3 is XOR: 0010 ^ 0011 = 0001 = 1, not 8. Write 1 << 3 or 2 ** 3.
Show Work
Formulas
From Boole to the CPU
AND, OR and NOT are the operations of George Boole’s algebra of logic, published in The Laws of Thought in 1854. In 1937 Claude Shannon showed in his master’s thesis that relay circuits could compute Boolean algebra, which is how every digital computer works: a bitwise AND on two 64-bit registers is 64 AND gates working at once, done in a single clock cycle.
The operators reached programming languages through BCPL and C, whose &, |, ^, ~, << and >> almost every later language copied. Java and JavaScript added >>> for a logical right shift, because their integers are always signed.
About This Calculator
This calculator applies AND, OR, XOR, NAND, NOR, XNOR, NOT, shift left and logical or arithmetic shift right to numbers entered in decimal, hex or binary, at 8, 16, 32 or 64 bits. It draws the operands and the result bit by bit and gives the answer in hex, unsigned and signed decimal and binary, with exact 64-bit arithmetic.
Everything runs in your browser; nothing is sent anywhere. To set, clear, test or rotate single bits, or count them, use the bit manipulation toolkit.
Related calculators: Bit Manipulation Toolkit, Two’s Complement Converter, and Number Base Converter.
Frequently Asked Questions
What does a bitwise AND do?
It compares two numbers bit by bit and keeps a 1 only where both have a 1. 12 is 1100 and 10 is 1010, so 12 AND 10 is 1000, which is 8. It is used to mask off bits: x AND 0xFF keeps the lowest byte, so 0xDEADBEEF AND 0xFF is 0xEF.
What is the difference between OR and XOR?
OR gives 1 where either bit is 1; XOR (exclusive or) gives 1 only where the bits differ, so two 1s give 0. 12 OR 10 is 1110 = 14; 12 XOR 10 is 0110 = 6. XOR with a mask flips those bits, and XORing twice with the same value gets the original back.
What does shifting left or right do?
Shifting left by n moves every bit n places up and fills with zeros, multiplying by 2ⁿ as long as no bits fall off the top: 1 << 5 = 32. A logical right shift fills with zeros and divides an unsigned number by 2ⁿ. An arithmetic right shift copies the sign bit in, so −16 >> 2 is −4.
Why is NOT 5 equal to −6?
NOT inverts every bit at the chosen width. 5 in 8 bits is 0000 0101, so NOT 5 is 1111 1010. Read as unsigned that is 250; read as a signed two’s complement number it is −6. In general, NOT x = −x − 1.
What does ^ mean in code?
In C, C++, Java, JavaScript, C# and Python, ^ is XOR, not a power. 2 ^ 3 is 0010 XOR 0011 = 0001, which is 1, not 8. Use pow(2, 3), 2 ** 3 or 1 << 3 for powers of two.
How do I use the Bitwise Calculator?
Just type your numbers. The answer shows up right away — there is no button to press. Change anything and it updates by itself.
Do I need to install or sign up for anything?
Not at all — it runs in the browser with nothing to install and no account. After it loads once, it even works without an internet connection.
Is my information private?
Yes. Everything happens in your browser. Nothing you type is sent to a server or saved anywhere.
Common Use Cases
Masking
0xDEADBEEF AND 0xFF = 0xEF keeps the lowest byte.
Subnets
192.168.1.130 AND 255.255.255.192: 0xC0A80182 & 0xFFFFFFC0 = 0xC0A80180, the network 192.168.1.128.
Flags
0b0101 OR 0b0010 = 0b0111 turns flag bit 1 on; XOR 0b0010 turns it off again.
Fast maths
1 << 10 = 1,024; −16 arithmetic-shifted right by 2 = −4.
Last updated: