Skip to main content
NyankoTools

Bitwise Calculator (AND/OR/XOR/NOT/Shift, Two’s Complement)

Pick two values, a bit width and an operation to see the result in binary, decimal and hex at once, with every set bit highlighted. Enter values in decimal, hex ("0xFF"), binary ("0b1010") or as negative numbers (two’s complement). BigInt keeps 64-bit math exact. For plain base conversion, use the Base Converter. Everything runs in your browser, so nothing you type is sent to a server.

🔒 Runs in your browser · Your data is never sent to a server

Result

Blue cells are 1 and gray cells are 0. The leftmost cell is the most significant bit, and rows wrap every 8 bits.

Notes

  • Values must fit the unsigned range of the selected width (0 to 255 for 8 bits) or the signed two’s complement range (-128 to 127). Negative numbers are converted to their two’s complement bits before the operation.
  • The results of NOT, NAND, NOR and XNOR are truncated to the selected width, so changing the width changes the upper bits.
  • Bits shifted out on the left are discarded. If the shift count is the bit width or more, shift left and logical shift right give 0, and arithmetic shift right fills with the sign bit.
  • Rotates wrap the overflowing bits around to the other end. The count is taken modulo the bit width.
  • Underscores and spaces inside a number are ignored (for example 0b1111_0000).

Glossary

Two’s complement

The usual way to store negative integers in bits. Flip every bit of the positive value and add 1. In 8 bits, -1 is 11111111 and -128 is 10000000. If the top bit is 1, the value is read as negative.

Logical vs arithmetic shift right

A logical shift fills the vacated top bits with 0. An arithmetic shift copies the sign bit, so a negative number stays negative and is divided by a power of two.

Rotate

A shift that feeds the bits falling off one end back in at the other end. It is common in hash functions and ciphers.

XOR (exclusive OR)

Gives 1 only when the two bits differ. XORing with the same value twice restores the original, which is why it appears in simple ciphers and flag toggling.

FAQ

How are negative numbers turned into bits?

They use two’s complement. In 8 bits, -1 becomes 11111111 (0xFF) and -128 becomes 10000000 (0x80). The signed decimal row shows the value read as negative whenever the top bit is 1.

What is the difference between >> and >>>?

They fill the vacated top bits differently. A logical shift (>>>) always fills with 0; an arithmetic shift (>>) copies the sign bit. In 8 bits, shifting 0x80 (-128) right by 1 gives 0x40 (64) logically and 0xC0 (-64) arithmetically.

Is 64-bit math exact?

Yes. The tool uses JavaScript BigInt, so values above 2^53 are not rounded. The largest 64-bit value is 18446744073709551615 (0xFFFFFFFFFFFFFFFF).

What happens if the shift count is larger than the bit width?

Shift left and logical shift right return 0, and arithmetic shift right fills everything with the sign bit. Rotates use the count modulo the bit width. In C and some other languages this case is undefined, so check your language rules before relying on it.

Share this page

↑↓ Select Enter Open Esc Close