Bitwise calculator
Enter two numbers in decimal, hexadecimal, binary or octal, choose the width in bits and a shift amount, and this tool shows the results of the common bitwise operations.
Results
Enter your values to see the result.
About this tool
It gives AND, OR, XOR, NOT and the left and right shifts, each in decimal, hexadecimal and binary. It helps with programming, flags and low-level work.
- How it is calculated
- numbers are held in the width you choose (two's complement for negative numbers); AND, OR and XOR work on each bit; NOT flips every bit within the width; a left shift multiplies by 2 and drops bits that leave the width; a right shift moves bits to the right and fills with zeros. Type decimal, 0x… (hexadecimal), 0b… (binary) or 0o… (octal).
- Worked example
- With First number: 12; Second number: 10; Width: 32 bits; Shift by: 2, the result is: First number (as stored): 12; Second number (as stored): 10; a AND b: 8; a OR b: 14; a XOR b: 6; NOT a: 4294967283; NOT b: 4294967285; a shifted left: 48; a shifted right: 3.
- Good to know
- Numbers are stored in the width you choose, using two's complement for negative values. AND, OR and XOR work on each bit, NOT flips every bit within the width, and a left shift drops the bits that leave the width. Prefix 0x for hexadecimal, 0b for binary and 0o for octal.
Frequently asked questions
How do I enter a hexadecimal or binary number?
Start it with 0x for hexadecimal, 0b for binary or 0o for octal, for example 0xFF or 0b1010. Numbers without a prefix are read as decimal.
Why is NOT a such a large number?
NOT flips every bit within the chosen width, so for a small positive number the result has many ones. With a 32-bit width, NOT 12 gives 4,294,967,283.
What does a right shift do?
It moves the bits to the right and fills with zeros, which divides a positive number by two for each step and drops the remainder.