Free Bitwise Calculator

Perform bitwise operations on integers and view results in decimal, hex, and binary.

Enter values and click Calculate.

How It Works

  1. Enter two numbers: Input the values you want to operate on, in decimal, binary (prefix 0b), or hexadecimal (prefix 0x).
  2. Select the operation: Choose AND, OR, XOR, NOT, left shift (<<), or right shift (>>).
  3. View the result: The output shows the result in decimal, binary, and hex simultaneously, with a bit-level visualization.

Why Use Bitwise Calculator?

Bitwise operations are fundamental in systems programming, cryptography, game development, graphics, networking, and embedded systems. Understanding how AND, OR, XOR, and shift operations manipulate individual bits is critical for tasks like setting/clearing flags, packing data into compact formats, and implementing efficient algorithms. This calculator shows the operation at the bit level so you can see exactly how each bit is affected.

Features

Frequently Asked Questions

What is XOR used for in programming?

XOR (^) is used for toggling bits, simple encryption/obfuscation, swap operations without a temp variable, parity checks, and hash mixing. It returns 1 when bits differ and 0 when they are the same.

What is the difference between << and >>?

Left shift (<<) moves all bits to the left, equivalent to multiplying by powers of 2. Right shift (>>) moves bits right, equivalent to dividing by powers of 2. Arithmetic right shift preserves the sign bit; logical right shift fills with zeros.

How do I set or clear a specific bit?

To set bit n: value |= (1 << n). To clear bit n: value &= ~(1 << n). To toggle bit n: value ^= (1 << n). To check if bit n is set: (value & (1 << n)) !== 0.

From Boolean algebra to silicon: how bitwise ops became universal

The bitwise operations every modern CPU implements come from two foundational papers published more than 80 years apart. In 1854, George Boole published «An Investigation of the Laws of Thought», defining the algebra of two-valued logic, AND, OR, NOT, and their identities. It was a philosophical work, not an engineering one. Then in 1937, a 21-year-old MIT graduate student named Claude Shannon wrote his masters thesis «A Symbolic Analysis of Relay and Switching Circuits», proving that Boolean algebra could describe electrical relay circuits and therefore that any logical computation could be physically implemented. This thesis is widely cited as the most important masters thesis of the 20th century and is the foundation of all digital electronics. Two's complement, the binary representation for negative numbers that every CPU uses, was patented in 1962 by Burroughs Corporation but had been used in the IBM 704 (1954) and other early machines. IEEE 754 standardised floating-point representation in 1985, fixing the bit layout that every JavaScript Number still uses, 1 sign bit, 11 exponent, 52 mantissa for binary64. Today, the C language operators & | ^ ~ << >> map almost directly to single CPU instructions, which is why bitwise code can be dramatically faster than the arithmetic equivalent.

The six operators, what they do at the bit level

Where bitwise actually earns its keep

Mistakes that bite

Why two's complement, and what it means at the bit level

Every modern CPU represents negative integers using two's complement. In a signed 8-bit byte, the values 0 to 127 are encoded as binary 0000_0000 to 0111_1111. Then −1 is encoded as 1111_1111, −2 as 1111_1110, down to −128 as 1000_0000. The reason: with this encoding, addition works the same way whether the inputs are signed or unsigned, the CPU does not need separate add-signed and add-unsigned instructions. The asymmetry is that the negative range is one larger than the positive (in 8 bits, −128 to +127), which is why Math.abs(INT_MIN) overflows in every language with fixed-width integers. The earlier sign-magnitude (one bit for sign, rest for magnitude) and one's-complement encodings existed in the 1950s-60s but lost out to two's complement because they had two representations of zero and required special-case hardware for negation.

More frequently asked questions

Why is ~5 equal to -6 instead of 250?

Because in two's complement (the encoding every modern CPU uses), flipping every bit of a positive number gives you -n - 1. So ~5 === -6 and ~0 === -1. In an unsigned 8-bit context, the same bit pattern as ~5 (binary 1111_1010) would represent 250. JavaScript treats the result as signed 32-bit, so you see -6. To get the unsigned interpretation: (~5) >>> 0 in 32-bit, which gives 4294967290, or mask to 8 bits with ~5 & 0xFF which gives 250.

Is XOR really an encryption?

XOR is the building block of every modern symmetric cipher, but XOR alone is not secure encryption. A one-time pad, XOR with a truly random key as long as the message, used exactly once, is information-theoretically unbreakable (Shannon, 1949). Reuse the key, or use a key shorter than the message, and frequency analysis breaks it trivially. Real ciphers like AES use XOR plus diffusion and substitution to amplify a short key into a stream of pseudo-random bytes that look like a one-time pad to anyone without the key. So «encrypt with XOR» is fine only for trivial obfuscation, never for real secrets.

When should I use BigInt instead of Number for bit manipulation?

Any time you need more than 32 bits of bitwise precision. JavaScript bitwise operators truncate Number operands to 32-bit signed integers before computing. If you need 64-bit masks (e.g., manipulating a 64-bit feature flag set, working with Linux mmap offsets, or implementing SHA-512), use BigInt: 0xFFFFFFFFFFFFFFFFn & 0xFFn === 255n. BigInt is slower than Number, ~3-10× depending on operation, so reserve it for the cases where 32 bits is genuinely too few.

How do I count the number of 1 bits in a number?

This is the population count or Hamming weight. Most modern CPUs have a single instruction for it (POPCNT on x86, VCNT on ARM). In JavaScript, no built-in, so use the bit-twiddling classic: let c = 0; while (x) { c += x & 1; x >>>= 1; }. Or the parallel SWAR trick from Hacker's Delight: x = x - ((x >> 1) & 0x55555555); x = (x & 0x33333333) + ((x >> 2) & 0x33333333); x = (x + (x >> 4)) & 0x0F0F0F0F; return (x * 0x01010101) >>> 24;, which counts the bits in a 32-bit integer in roughly a dozen cycles.

Is my data sent anywhere when I use this calculator?

No. Every operation runs in your browser's JavaScript engine, no network calls happen during a calculation. Open the Network tab in DevTools and click Calculate, you will see zero outbound requests. Safe for sensitive masks, keys, or proprietary bit-layout work.

Related Tools

Binary Text Number Base Chmod Calculator Hash Generator