Bitwise Calculator
Run AND, OR, XOR, NOT and shifts on integers in any base at 8-64 bit width — entirely on this device.
0xF0 & 0x0F- Octal
- 0o00000000360
- Decimal
- 240
- Signed
- 240
- Hex
- 0x000000F0
4 set bits
- Octal
- 0o00000000017
- Decimal
- 15
- Signed
- 15
- Hex
- 0x0000000F
4 set bits
- Octal
- 0o00000000000
- Decimal
- 0
- Signed
- 0
- Hex
- 0x00000000
0 set bits
Press ? for shortcuts
Do it offline:$ printf '0x%X\n' "$(( 0xF0 & 0x0F ))"
How to use it
- Type operand A, then B; a 0x, 0b or 0o prefix picks that operand's base, and bare digits follow the selector.
- Choose the operator — AND, OR and XOR use both operands, NOT flips A alone, and the shifts read B as a bit count.
- Set the width to 8, 16, 32 or 64 bits; operands fold into that many low bits.
- Read the result row: binary, octal, decimal, signed decimal, hex and a set-bit count, each with a copy button.
- Copy the 0x result, download a report, or permalink the whole setup in the URL.
Give it two operands and an operator — AND, OR, XOR, NOT, or a left, arithmetic-right or logical-right shift — and read the answer as bits, octal, decimal, signed decimal and hex at your chosen 8, 16, 32 or 64-bit width. A 0x, 0b or 0o prefix sets each operand's base, and every operation runs on this device with no upload.
How it works
A width is a mask: each operand is first reduced to its low w bits — ANDed with 2^w − 1 — so 8-bit math never sees a ninth bit. AND, OR and XOR then combine the operands bit by bit; NOT flips A against that mask, so ~0x0F at 8 bits is 0xF0.
The signed-decimal row reads the same bits as two's complement: at 8 bits 0xFF is 255 unsigned and -1 signed. A negative operand simply stores that pattern, and both readings stay on screen together.
Left shift multiplies within the width — 0x1 << 4 is 0x10. The right shifts split on the top bit: arithmetic >> copies the sign while logical >>> feeds in zeros, so 0x80 >> 1 is 0xC0 but 0x80 >>> 1 is 0x40. A 64-bit >>> stays exact where a 32-bit engine truncates.
Examples
0xF0 & 0x0F= 0x00000000 · 0 unsigned · 0 signed · 0 of 32 bits set0xF0 is 11110000 and 0x0F is 00001111 — no bit is set in both, so AND clears everything. That is how a mask drops a field.
0x2A ^ 0xFF= 0xD5 · 213 unsigned · -43 signed · 5 of 8 bits setXOR against all ones flips every bit: 00101010 becomes 11010101, the one's complement of A. As a signed 8-bit value it reads -43.
0xFFFFFFFFFFFFFFFF >>> 32= 0x00000000FFFFFFFF · 4294967295 unsigned · 4294967295 signed · 32 of 64 bits setShifting 64 ones right by 32 leaves the low half set; a native >>> would coerce to 32 bits and drop the top word.
Every example on this page is executed against the same engine that powers the tool, on every build.
Gotchas worth knowing
A negative operand becomes its two's-complement bits
Enter -1 at 8 bits and it stores as 11111111 — 0xFF — tagged two's-complement. AND it with 0xFF and the result stays 0xFF: minus one carries every bit.
A value too wide for the width keeps its low bits
0x1FF needs nine bits; at width 8 only the low eight survive, so it folds to 0xFF with a wrap chip. Widen to 16 and the ninth bit returns.
Right shift comes in two flavors
On 0x80 at 8 bits, arithmetic >> copies the set sign bit for 0xC0, while logical >>> pulls in zeros for 0x40. Left shift has one form.
Shifting by the width or beyond saturates
At or past the width, no original bit survives: left and logical-right shifts give all zeros, an arithmetic right shift of a negative gives all ones.
Prefixes and separators are read per operand
0x, 0b and 0o outrank the base selector, so a hex value can meet a binary one. Underscores and spaces are stripped and counted — 0xDEAD_BEEF loses one and parses as 0xDEADBEEF.
The shell equivalent has real limits
POSIX $(( )) is 64-bit signed with one arithmetic >> and no width control, matching AND, OR, XOR and left shift only; the width toggle and logical >>> have no one-liner.
Common errors
`G` is not a valid hexadecimal digit (0-9, A-F)- It names the base, prints the digits it accepts and points at the character it stopped on — usually the prefix or selector is the wrong base.
Shift amount must be 0 or greater.- Shift counts are unsigned distances, so a negative one is meaningless; to move bits the other way, swap the left and right shift operators.
Integers only for now — fractional base conversion is planned- A decimal point in an operand or a count stops the run — bit operations act on whole patterns — and the dot is marked where you typed it.
Nothing to convert — the input is empty- Operand A is always required, and B is required for every operator except NOT; an empty required field halts before masking.
Input is larger than the 1 MB limit for this tool.- Past 1 MB of characters the page refuses the whole operand rather than part of it; the command-line equivalent below has no size ceiling.
FAQ
What is the difference between >> and >>>?
Both move bits right but differ on the vacated top. Arithmetic >> repeats the sign bit, so a negative stays negative — 0x80 >> 1 is 0xC0 at 8 bits. Logical >>> feeds in zeros, giving 0x40. Use >> for signed math, >>> for raw patterns.
Why does a negative number show as a large positive one?
The unsigned row prints the raw pattern and the signed row reads it as two's complement. At 8 bits -1 is stored as 11111111 — 255 unsigned, -1 signed. Same bits; the width decides how the top one is weighed.
Can it run 64-bit operations without losing precision?
Yes — every value is a big integer, so 64 bits stay exact: 0xFFFFFFFFFFFFFFFF >>> 32 returns 0xFFFFFFFF with no rounding. A browser's native >>> collapses to 32 bits first and drops the high word.
Keyboard shortcuts
- ⌘/Ctrl + Enter
- Recompute now; results also refresh on every edit.
- ⌘/Ctrl + C
- Copy the 0x result when no text is selected; a focused operand field keeps its own copy.
- ⌘/Ctrl + Shift + C
- Force-copy the 0x result over any selection.
- ⌘/Ctrl + S
- Save a plain-text report — operands, operator, width and result — past the browser save dialog.
- t
- Switch the theme unless an operand field has focus.
- ? or ⌘/Ctrl + /
- Show this page's keyboard reference.
- Esc
- Close the top dialog; the operands stay untouched.