Bitwise calculator
Shift and mask 256-bit numbers — AND, OR, XOR, NOT and bit shifts.
The calculation
Values are read as hexadecimal. Everything recalculates as you type.
With or without 0x — ff and 0xff both mean 255.
A bit is 1 in the answer only when it is 1 in both values. This is how you mask a field out of a packed number.
Bits set to 1 here survive; everything else is cleared. 0xff keeps the last byte.
The answer shows up here
Enter a value on the left and you'll get the result in decimal, hexadecimal and binary at the same time.
Every operation, in one line each
The same six operators Solidity gives you.
AND (&)
A bit is 1 in the answer only when it is 1 in both values. This is how you mask a field out of a packed number.
OR (|)
A bit is 1 in the answer when it is 1 in either value. This is how you switch a flag on.
XOR (^)
A bit is 1 in the answer when the two values disagree. XOR with the same value twice gets you back where you started.
NOT (~)
Every 1 becomes 0 and every 0 becomes 1. On whole numbers that is the same as -(x + 1), so the answer comes out negative.
SHL (<<)
Moves every bit left, padding with zeros. Shifting left by n multiplies by 2 to the power n.
SHR (>>)
Moves every bit right, dropping what falls off the end. Shifting right by n divides by 2 to the power n and rounds down.