Bitwise Calculator
Compute AND, OR, XOR, NAND, NOR, XNOR, NOT, shifts and rotates on two 8-, 16-, 32- or 64-bit integers, with results in decimal, hex, octal and binary.
A and B are 32-bit integers: any value from -2,147,483,648 to 4,294,967,295. From 2,147,483,648 up, a value is read as its bit pattern, so 4294967295 and -1 are the same 32 bits.
Bits — click one to flip it
80x000000080o000000000100000 0000 0000 0000 0000 0000 0000 1000
1 of 32 bits set · parity odd · highest set bit 3 · lowest set bit 3
Hex, octal and binary are shown as unsigned 32-bit values.
What this bitwise calculator does
Enter two integers as decimal (like 255), hexadecimal (0xFF), octal (0o755) or binary (0b1010), pick an operation and a width — 8, 16, 32 or 64 bits — and instantly see the result in decimal, hexadecimal, octal and binary. It supports AND, OR, XOR, NAND, NOR, XNOR, NOT (unary on A), left shift (A << B), arithmetic right shift (A >> B), logical right shift (A >>> B), and rotate left and rotate right, which JavaScript has no operator for. Set, clear, toggle and test bit B act on the bit of A at position B, and a row of buttons shows the bits of A so you can flip any of them with a click. Under the binary answer, a line counts the bits set in the result, says whether that count is even or odd (its parity), and names the highest and lowest set bit (none for zero), read off the unsigned pattern so -1 has every bit set. Every value is treated as a two's complement integer of the chosen width. The default, 32 bits, is the width of JavaScript's own bitwise operators and of an int in C and most systems languages; the work is done on BigInt, so a 64-bit value keeps every digit, even past 2^53, where a JavaScript Number starts to round. A and B may be anything from the most negative signed value of the width to its largest unsigned one (-2,147,483,648 to 4,294,967,295 at 32 bits), and a value past that is refused rather than silently wrapped.
Signed, unsigned and two's complement
The first decimal row is always the signed reading, so at 32 bits NOT 0 reads -1, and so does -1 >>> 0 — and whenever the top bit is set, the unsigned reading, 4294967295, is printed in its own row. The hex, octal and binary outputs are shown as unsigned patterns of the chosen width, which is why -1 at 32 bits appears as 0xFFFFFFFF, 0o37777777777 and all-ones binary. Arithmetic right shift copies the sign bit, while logical right shift fills with zeros — a common source of bugs, and easy to compare side by side here; a line under B says what the chosen shift, rotate or bit operation does.
Frequently asked questions
What is the difference between >> and >>> ?
A >> B is an arithmetic right shift that preserves the sign bit, so negative numbers stay negative. A >>> B is a logical right shift that fills the vacated high bits with zeros, so a shift of 1 or more never sets the sign bit. The first decimal row is always the signed reading of the result; whenever the top bit is set (bit 31 at 32 bits), the Unsigned decimal row gives the unsigned value too, so -1 >>> 0 reads -1 and 4294967295.
Can it rotate bits, or do NAND, NOR and XNOR?
Yes. Rotate left (ROL) and rotate right (ROR) carry the bits that fall off one end of the word back in at the other, at the width you choose, for a count from 0 to one less than the width (0 to 31 at 32 bits). NAND, NOR and XNOR are in the same list, each the negation of its base gate, so ~(A & B) is one step rather than two.
Can I enter hexadecimal, octal or binary values?
Yes. Type values in decimal (for example 42), with a 0x prefix for hex (0x2A), a 0o prefix for octal (0o755 — the way file permissions are written) or a 0b prefix for binary (0b101010). You can also use a leading minus sign, such as -5 or -0x10.
Can I flip a bit by clicking it, or set, clear and test a single bit?
Yes. Open Bits — click one to flip it for a row of toggle buttons showing every bit of A, highest first, and of B too while B is an operand rather than a count. Pressing a bit flips it and rewrites the value in the notation you typed it in, so a hex value stays hex. The operation list also has set bit B, clear bit B, toggle bit B and test bit B, which act on the bit of A at position B, counted from the lowest, and take the same range as a shift count.
Can it count the bits that are set in the result?
Yes. A line under the binary answer gives how many bits of the result are set (its population count), whether that count is even or odd (its parity), and the positions of the highest and lowest set bits, counted from the lowest; a zero result has neither, so both read none. It reads the unsigned pattern, so a negative result such as -1 counts every bit as set.
Can it work at 8, 16 or 64 bits?
Yes. The Width select offers 8, 16, 32 and 64 bits, and the page opens at 32. Every operation, the range A and B may take, the bit buttons and the count of set bits follow the width, so at 8 bits -8 is 0xF8 and NOT 0 is 255 unsigned, and a 64-bit value keeps every digit, because the work is done on BigInt rather than on JavaScript's 32-bit operators.