Bitwise calculator
Run AND, OR, XOR, NOT, shifts, unsigned shifts and rotations on integers with 0x / 0b / 0o or decimal input, 8–64 bit widths, and decimal, binary, octal, hex plus popcount output.
Runs in your browserEvery computation happens in your browser — your data never leaves this device.
Shift counts at or beyond the bit width saturate (left / unsigned right shifts yield 0, arithmetic right shifts fill with the sign bit); rotation counts wrap around the width.
Result
880x080o1010b0000 1000
What this tool does
- Work out permission bitmasks: `0b1100 & 0b1010` gives 0b1000, showing exactly which flags are set in both.
- Debug a protocol or register at 8/16/32/64 bits and see the unsigned value, the two’s-complement value, hex and 4-bit-grouped binary together.
- Check shifts and rotations: left shifts that overflow saturate to 0, arithmetic right shifts fill with the sign bit and rotation counts wrap around the width — the rules are documented on the page.
- Count set bits (popcount) for Hamming weight, bitmap cardinality or hash-bit checks.
Example
Input
A = 0b1010, B = 0b1100, operator AND, width 8
Output
Decimal (unsigned) 8 · Decimal (two’s complement) 8 · Hex 0x08 · Octal 0o10 · Binary 00001000 · Groups of 4 bits 0000 1000 · Set bits 1
ANDing the two 4-bit values gives 1000, padded to 00001000 at 8-bit width. Switch to `0xFF << 4` at width 8 and the result truncates to 240, which reads as −16 in two’s complement.
Frequently asked questions
Which input formats are accepted?
Decimal `255`, hex `0xFF`, binary `0b1010` and octal `0o17` all work, with an optional sign and `_` as a digit separator (`0b1010_1010`). Empty input reports “Enter a number”, and a prefix-less hex value like `FF` is treated as an invalid integer.
Why does NOT need a bit width?
Because the length of a bitwise complement depends on the width: `~0x0F` is 0xF0 at 8 bits but 0xFFFFFFF0 at 32. The tool always masks to the width you picked, so a wrong width setting produces a surprising — but correct — result.
What happens when the shift count exceeds the width?
It saturates rather than wrapping. Left shift and unsigned right shift past the width give 0, and arithmetic right shift fills with the sign bit (0 for positive, all ones for negative). Rotations are different by design: ROL/ROR take the count modulo the width, so rotating left by 8 at width 8 changes nothing. That deliberately differs from JavaScript’s `<<`, which only uses the low 5 bits.
Why is hex zero-padded but octal not?
Hex is padded to a fixed width for the chosen size (2 digits at 8 bits, 8 at 32 bits) so you can compare it byte by byte. Octal does not align to a 4-bit boundary, so it shows only significant digits, like 0o377. Use the hex or binary row when you need a fixed width.
How are negative numbers handled?
A negative input is truncated to its unsigned value at the chosen width before the operation, so -1 at 8 bits becomes 0xFF. The output shows both the unsigned decimal and the two’s-complement signed decimal so you do not have to guess. Values outside the 64-bit range are rejected.
Keywords:bitwise位运算andorxornotshift左移右移循环移位rotatepopcount位宽binaryhex