Bitwise Calculator
Type two numbers in decimal, hexadecimal (0xCA) or binary (0b1100_1010), choose 8, 16, 32 or 64 bits, and see AND, OR, XOR, their inverses, NOT, shifts and rotations at once. Each result appears in binary, hex, unsigned decimal and signed decimal. Everything runs in your browser.
Type decimal (202 or -54), hexadecimal (0xCA) or binary (0b1100_1010). A negative number is stored in two's complement.
| Operation | Binary | Hex | Unsigned | Signed |
|---|---|---|---|---|
| A | 1111 0000 | 0xF0 | 240 | -16 |
| B | 0011 1100 | 0x3C | 60 | 60 |
| A AND B | 0011 0000 | 0x30 | 48 | 48 |
| A OR B | 1111 1100 | 0xFC | 252 | -4 |
| A XOR B | 1100 1100 | 0xCC | 204 | -52 |
| A NAND B | 1100 1111 | 0xCF | 207 | -49 |
| A NOR B | 0000 0011 | 0x03 | 3 | 3 |
| A XNOR B | 0011 0011 | 0x33 | 51 | 51 |
| NOT A | 0000 1111 | 0x0F | 15 | 15 |
| A << 2 | 1100 0000 | 0xC0 | 192 | -64 |
| A >> 2 (logical) | 0011 1100 | 0x3C | 60 | 60 |
| A >> 2 (arithmetic) | 1111 1100 | 0xFC | 252 | -4 |
| Rotate A left 2 | 1100 0011 | 0xC3 | 195 | -61 |
| Rotate A right 2 | 0011 1100 | 0x3C | 60 | 60 |
A has 4 bits set to 1 out of 8.
AND keeps a bit only where both inputs have it, OR keeps it where either has it, and XOR keeps it where exactly one has it. NAND, NOR and XNOR are those results flipped. NOT flips every bit of A within the chosen width. A left shift moves bits up and fills with zeros. A logical right shift fills the top with zeros, while an arithmetic right shift copies the sign bit, so a negative number stays negative. Rotations move bits out of one end and back in at the other. Results are exact for 64 bits. Everything is worked out in your browser and nothing is uploaded.
Related Tools
[5 suggestions]Number Base Converter
Convert whole numbers between binary, octal, decimal, hex and any base from 2 to 36, with two's complement.
Developer & WebChmod Calculator
Work out Unix file permissions: tick boxes, or type octal, an ls -l string or a symbolic change, and get the chmod command.
Developer & WebSubnet Calculator
Work out the network, broadcast, host range, usable hosts and masks of an IPv4 address with a prefix or mask, and split a block into subnets.
Developer & WebText to Binary Translator
Convert text to binary, hex, decimal, or octal and decode it back, using UTF-8 bytes.
Developer & WebHash Generator (MD5, SHA-1, SHA-256, SHA-512)
Generate MD5, SHA-1, SHA-256, and SHA-512 cryptographic hashes live from any text using the native Web Crypto API.
Developer & WebAbout the Bitwise Calculator
Bitwise operations work on the individual bits of integers. AND keeps a bit where both numbers have it, OR where either has it, XOR where exactly one has it, and NAND, NOR and XNOR are those results with every bit flipped. NOT flips every bit of the first number within the chosen width, so NOT 5 is 250 in 8 bits and -6 as a signed value. A left shift moves the bits toward the top and fills with zeros, which multiplies by a power of two until bits fall off the top. A logical right shift fills the top with zeros, and an arithmetic right shift copies the sign bit, so a negative number stays negative: -8 shifted right by 1 is -4. A rotation moves bits out of one end and back in at the other, so nothing is lost. Signed values use two's complement, in which the top bit has a negative weight, so 0xFF is 255 unsigned and -1 signed in 8 bits. A negative decimal input is converted to that form, and a number that does not fit the width is refused with the allowed range. Arithmetic uses exact big integers, so 64-bit values keep every digit, which JavaScript numbers cannot do. The results were checked against JavaScript's own 32-bit operators. Nothing is uploaded.
What do AND, OR and XOR do?▾
AND gives a 1 only where both bits are 1. OR gives a 1 where either bit is 1. XOR gives a 1 where the bits differ. For 0xF0 and 0x3C in 8 bits, AND is 0x30, OR is 0xFC and XOR is 0xCC.
What is the difference between a logical and an arithmetic shift?▾
A logical right shift fills the new top bits with zeros. An arithmetic right shift copies the sign bit, so a negative number stays negative. Shifting the 8-bit value 0xF8 right by 1 gives 0x7C logically but 0xFC (which is -4) arithmetically.
How are negative numbers stored?▾
In two's complement: flip all the bits and add 1. In 8 bits, -1 is 11111111, which is 255 when read as unsigned. The top bit is the sign. The tool shows both the signed and unsigned reading of every result.
Why does NOT 5 give 250?▾
NOT flips every bit within the width. In 8 bits, 5 is 00000101, so NOT is 11111010, which is 250 unsigned or -6 signed. In 32 bits the same operation gives 4,294,967,290, so the width matters.
Can it handle 64-bit numbers exactly?▾
Yes. The calculator uses big integers, so every one of the 64 bits is kept. Ordinary JavaScript numbers lose precision above 2 to the power of 53. Nothing you enter is uploaded.