Developer Bitwise

Bitwise calculator

Values are in
First value
Second value
Operation
Result 8
32-bit operations
Every operation on these two
In decimal 8
In binary 1000
In hex 0x8
A AND B 8
A OR B 14
A XOR B 6
NOT A 4294967283
32-bit operations

AND masks — it keeps only the bits set in both, so ANDing with 0x0F keeps the low nibble and clears the rest. OR sets — it turns bits on without disturbing the others. XOR toggles, and applying it twice with the same value returns the original, which is why it turns up in simple ciphers and in swapping without a temporary variable.

Operations are 32-bit, which is what JavaScript bitwise operators use. Values above 2³²−1 will wrap.

Advertisement
320 × 100

Bitwise operations compare two numbers bit by bit. 12 AND 10 is 8, because only the 8-bit is set in both. OR gives 14, XOR gives 6. Operations here are 32-bit.

How to use bitwise operations

1 Choose the base your values are written in.
2 Enter both values.
3 Pick an operation, or just read all four results.
4 Check the binary row to see which bits survived.

The binary row is the one to read while learning. Bitwise operations are obvious once you can see the columns lining up — 1100 AND 1010 gives 1000 because only the leftmost column has a 1 in both. Everything else, including the masking and flag-setting idioms that fill real code, follows from that column-by-column comparison. Note that NOT operates on all 32 bits, so NOT 0 is 4294967295 rather than 1.

Questions

Keeps only bits set in both values. It is how masks work.

Advertisement
300 × 250
Was this tool any good?
INTERNAL SIGNAL ONLY · WE USE IT TO FIND TOOLS WORTH REBUILDING