Overview
A focused 32-bit bitwise calculator: AND, OR, XOR, NAND, NOR, XNOR, NOT, and left, arithmetic-right, and unsigned-right shifts. Enter operands in decimal, hex, or binary and read the result in all three bases at once - with the 32-bit binary laid out in groups of eight so individual bits are easy to point at.
How It Works
Choose the input base, type operand A (and B, except for NOT), and press the operation you want. The result cards show the unsigned decimal, uppercase hex, grouped 32-bit binary, and the signed 32-bit interpretation; click any card to copy it. Everything recomputes live as you edit, so you can flip bits and watch carry-free arithmetic respond instantly.
Step-by-Step Usage Guide
- Pick the base your values are already written in - decimal, hex, or binary.
- Enter operand A, and B if the operation needs two operands.
- Click the operation button; the four result cards update immediately.
- Copy the representation you need, or read the grouped binary to verify individual bits.
Technical Specifications & Standards
JavaScript bitwise operators work on 32-bit two's complement integers, which is exactly the model most C-style code assumes, so this tool mirrors the language rather than inventing arbitrary-width arithmetic. Shift amounts are masked to the low five bits (0-31) per the specification, so a shift by 32 is a shift by 0, matching real hardware behaviour. The three shifts differ in a way the display makes visible: SHL fills with zeros, SHR (arithmetic) keeps the sign bit, and USHR (unsigned) always fills with zeros, which is why -16 >> 2 and -16 >>> 2 disagree. NAND, NOR, and XNOR are computed as the complement of the base operation, since they are the functionally-complete inversions used in circuit design. Hex input accepts an optional 0x prefix, binary accepts 0b, and results are reported both signed and unsigned because the same 32 bits legitimately mean two numbers.
Targeted Use Cases
- Working out flag masks: which bits does 0xF0 | 0x0F set, and what does ~mask clear?
- Debugging a protocol header - paste the binary field and shift or mask out the sub-fields.
- Checking that (a ^ b) ^ b really returns a, the trick behind swap-without-temp and checksums.
- Understanding why -1 >>> 0 is 4294967295 while -1 >> 0 stays -1.
Notes & Gotchas
- Remember shifts are masked to 0-31; shifting by 32 or more does not move bits in 32-bit arithmetic.
- Prefer USHR when you intend a logical, non-negative shift on values that may be negative.
- Hex is the compact review format - 8 hex digits map one-to-one onto the 32 bits.
- For numbers beyond 32 bits, use a big-integer library instead; the answers here would silently wrap.
Frequently Asked Questions
Why does NOT of 0 give 4294967295?
NOT flips all 32 bits. In two's complement, ~0 is -1, and read unsigned that same bit pattern is 4294967295. Both readings are shown because both are correct for different contexts.
What is the difference between SHR and USHR?
SHR is the arithmetic shift: it copies the sign bit into the vacated positions, preserving the sign of negative numbers. USHR shifts in zeros regardless of sign, so -16 >>> 2 is a huge positive number while -16 >> 2 is -4.
Can I use operands larger than 32 bits?
No. Inputs are coerced to signed 32-bit integers, matching JavaScript's bitwise operators. For 64-bit or arbitrary-precision bit work you need BigInt or a dedicated library.
Does the base selector change the stored value?
No - base only changes how you type and read numbers. The computation is always on the same 32-bit values, and you can switch bases at any time without changing the result.