Bitwise Calculator
Compute bitwise AND, OR, XOR, NOT, shifts and rotates at 8, 16, 32 or 64 bits with a live bit grid.
- Hexadecimal
- 0x00000030
- Unsigned decimal
- 48
- Signed decimal
- 48
- Octal
- 0o60
- Binary
- 0000 0000 0000 0000 0000 0000 0011 0000
0x000000F0 AND 0x0000003C = 0x00000030 (240 & 60 = 48, 32-bit)
Bit grid (click a bit in row A or B to flip it)
Operator reference
| Operator | Meaning | Example (8-bit) |
|---|---|---|
& | 1 only when both bits are 1 | 0xF0 & 0x3C = 0x30 |
| | 1 when either bit is 1 | 0xF0 | 0x3C = 0xFC |
^ | 1 when the two bits differ | 0xF0 ^ 0x3C = 0xCC |
~ | flips every bit of A | ~0xF0 = 0x0F |
<< | shift left, zeros fill in | 0x0F << 2 = 0x3C |
>> | arithmetic right shift, copies the sign bit | 0xF0 >> 2 = 0xFC |
>>> | logical right shift, zeros fill in | 0xF0 >>> 2 = 0x3C |
| ROL | rotate left, bits wrap around | 0x81 ROL 1 = 0x03 |
| ROR | rotate right, bits wrap around | 0x81 ROR 1 = 0xC0 |
How it works
Type two values in decimal, hex (0x), binary (0b) or octal
(0o), pick an operation and the answer appears as you type. Every result is shown
five ways at once: hexadecimal, unsigned decimal, signed (two's complement) decimal, octal and a
grouped binary pattern, so you can check a bitmask, a register value or a permission flag without
a second lookup. The bit grid underneath shows A, B and the result bit by bit, and clicking any
bit in row A or B flips it so the operands and the answer update together.
All arithmetic uses JavaScript BigInt on fixed-width two's complement integers, so
8-, 16-, 32- and 64-bit results are exact. The operators follow the C semantics of ISO/IEC 9899
(§6.5.10–6.5.12) and, for >>>, the unsigned right shift of
ECMAScript (ECMA-262): >> is arithmetic and copies the sign bit, while
>>> is logical and shifts in zeros. Shift counts of the bit width or more
give 0 (or all sign bits for >>) instead of the undefined behaviour C allows.
ROL and ROR are not C operators; they use the usual rotate definition with the count taken
modulo the width. Worked check: at 32 bits -8 >> 1 is -4
(0xFFFFFFFC) while -8 >>> 1 is 2147483644
(0x7FFFFFFC). Nothing is uploaded: the page is plain JavaScript, works offline and
has no accounts or ads.
Frequently asked questions
What is the difference between >> and >>> ?
Both shift bits to the right, but they fill the vacated top bits differently. The arithmetic shift >> copies the sign bit, so a negative number stays negative: at 32 bits -8 >> 1 is -4, or 0xFFFFFFFC. The logical shift >>> always shifts in zeros, so the same input gives 2147483644, or 0x7FFFFFFC. Pick Arithmetic shift right for signed integers and Logical shift right for raw bit patterns, flags and hashes.
How do I calculate a bitwise AND by hand?
Write both numbers in binary, line them up, and put a 1 in the answer only where both bits are 1. For 0xF0 AND 0x3C that is 11110000 AND 00111100, which gives 00110000, or 0x30 in hex and 48 in decimal. OR sets a bit when either input has it, and XOR sets a bit only when the two inputs differ. The bit grid on this page stacks the three rows so you can read the columns off directly.
Why does the answer change when I change the bit width?
Every value is stored in a fixed number of bits, and NOT, shifts and rotates all depend on how many. NOT 0xF0 is 0x0F in 8 bits but 0xFFFFFF0F in 32 bits, because the extra 24 bits get flipped from 0 to 1. The same pattern also reads as a different signed number: 0xFFFFFF0F is -241 in 32-bit two's complement. Set the bit width to match the type you are working with, such as 8 for a byte, 32 for an int or 64 for a long.