Bitwise Calculator
Beta: this tool hasn't been fully reviewed yet. Double-check results before relying on them.
Inputs
Decimal, 0x hex, 0b binary or 0o octal; negative numbers allowed.
The second operand, or the number of places to shift.
Numbers wrap around at this width, as in a CPU register.
Results
- Result (signed)
- —
- Unsigned
- —
- Hexadecimal
- —
- Octal
- —
| a | |
|---|---|
| b | |
| = |
Your input is too long to share as a link, so the page address no longer includes it.
Bitwise operations work on the individual 0s and 1s of a number: AND keeps the bits set in both, OR the bits set in either, XOR the bits set in just one, NOT flips them all, and shifts slide them left or right. They are the basis of flags, masks, permissions and fast arithmetic in code.
How to use it
- Type a and, for two-operand operations, b.
- Pick the operation and the width.
- Read the result in signed and unsigned decimal, hex and octal, and compare the bits.
Examples: 12 AND 10 = 8 (1100 & 1010 = 1000). 0xF0 XOR 0xFF = 15 (0x0F). NOT 0 at 8 bits is −1 signed, 255 unsigned. 1 « 31 at 32 bits is −2,147,483,648 signed.
Questions and answers
Why does the same result have a signed and an unsigned value?
The bits are the same; only the reading differs. In two’s complement, a set top bit means a negative number, so 0xFF at 8 bits is 255 unsigned and −1 signed.
What is the difference between >> and >>>?
Both shift right. The arithmetic shift (») copies the sign bit into the gap, so negative numbers stay negative; the logical shift (»>) fills with zeros. JavaScript and Java have both; C uses » for either, depending on the type.
What happens to bits shifted past the edge?
They are dropped, and numbers wider than the chosen width wrap around, as they would in a register of that size.
Link with pre-filled values
Add # and these parameters to the end of this page's address to open the tool with values already filled in.
| Parameter | What it sets |
|---|---|
a | First integer: decimal, 0x hex, 0b binary or 0o octal. |
op | Operation: and, or, xor, nand, nor, not, shl, shr or sar. |
b | Second integer or shift count. |
bits | Width: 8, 16, 32 or 64. |
Example: https://toolabelle.com/bitwise-calculator/#a=0xF0&op=xor&b=0xFF&bits=8