Bitwise calculator
AND / OR / XOR / NOT / shifts on integers, shown in binary, octal, decimal and hex. 64-bit two's-complement width. Runs on your device.
Runs on your device. The file is never uploaded.
Bitwise calculator runs AND, OR, XOR, NOT, SHL or SHR over two integers, printing decimal, hex, octal and binary. Both operands accept 0x, 0b and 0o literals and are masked to 64 bits with BigInt. The decimal line is signed, so a result with bit 63 set reads negative while the other three lines stay unsigned.
Questions
What number formats can I type in?
Decimal, or a prefixed literal: 0x for hex, 0b for binary, 0o for octal. Both operands accept any of them, so you can AND 0xff with 0b1010. Anything else is refused with a message saying your value is not a valid integer (decimal, 0x hex, 0b binary, or 0o octal). The defaults are 12 and 10 with the AND operation.
How wide is the arithmetic?
64 bits. Both operands are masked to 64 bits before the operation and the result is masked again, so anything above bit 63 is discarded. The work is done with BigInt, so there is no silent 32-bit truncation of the kind JavaScript applies to its own & and | operators.
Why is my decimal result negative?
Because the decimal line is read as two's complement. If bit 63 of the result is set, 2^64 is subtracted and the signed value is shown, which is what a C int64_t would print. The hex, octal and binary lines show the same bits unsigned, so one result can read as decimal -1 and hex 0xffffffffffffffff at the same time.
What happens if I shift by more than 63?
The shift count is masked to its low 6 bits, so a shift of 64 shifts by 0 and a shift of 70 shifts by 6. That matches how a shift instruction behaves on x86 and ARM. SHL discards bits pushed off the top. SHR is a logical shift on the masked, unsigned value, so it fills with zeros rather than with the sign bit.
Does the second operand matter for NOT?
No. NOT reads only the first operand, inverts it and masks the result back to 64 bits, so whatever sits in the B field is ignored. The field stays on the page because the other five operations need it, so leave whatever is in it and read only the result.
What do I get back?
Four lines describing one result: decimal as a signed 64-bit value, hex with an 0x prefix, octal with 0o and binary with 0b. There is no zero padding, so a small result gives a short binary string rather than 64 characters.