Developer Tools
Bitwise calculator.
AND, OR, XOR, NOT and bit shifts on 8, 16, 32 or 64-bit values. Enter decimal, hex, binary or octal, see the signed and unsigned result and the bits lined up. Runs in your browser.
Input
Result
Enter values, then press Calculate.
How it works
- Width: A and B are read as a bit pattern of the chosen width. A value is accepted from -2n-1 to 2n-1 (8-bit: -128 to 255); negative inputs become their two's complement pattern, so -1 and 255 are the same 8 bits. The signed view of a result is two's complement.
- &, |, ^: AND is 1 only where both bits are 1, OR is 1 where either is, XOR is 1 where they differ.
1100 & 1010 = 1000,1100 | 1010 = 1110,1100 ^ 1010 = 0110. - ~ (NOT): flips every bit within the width. At 8 bits, ~5 is 250 unsigned and -6 signed.
- << (left shift): moves bits toward the top and fills with 0. Bits shifted past the top are discarded.
- >> (arithmetic right shift): moves bits down and copies the sign bit into the gap, so negative numbers stay negative. >>> (logical right shift): fills with 0 instead.
- Shift count: a whole number from 0 to width-1. JavaScript itself only applies these operators to 32-bit integers and takes the count modulo 32; this tool applies the same definitions at the width you choose and rejects counts outside the range instead of wrapping them.
- Precision: uses BigInt, so 64-bit values are exact. Nothing is sent anywhere.
Sources: MDN, JavaScript operators (see <<, >>, >>>); Wikipedia, Bitwise operation. Related: Two's Complement Calculator, IEEE 754 Float Converter, Binary Converter.