Bitwise Operations Calculator

Perform bitwise AND, OR, XOR, NOT, left shift, and right shift on integers.
See results in binary, decimal, hexadecimal, and octal with step-by-step breakdown.

Bitwise Result

What are bitwise operations?

Bitwise operations work directly on the binary representation of an integer, one bit at a time. Each bit position is handled independently, with no carry between positions, which is what separates them from ordinary arithmetic. They cost about as little as anything a CPU (Central Processing Unit) can do, usually a single clock cycle, and that is why they turn up everywhere in embedded firmware, networking code, compression, and cryptography.

The six operations

Operation Symbol Result bit is 1 when Typical use
AND & both input bits are 1 masking out unwanted bits: value & mask
OR | either input bit is 1 switching a flag on: value | flag
XOR ^ exactly one input bit is 1 toggling: value ^ toggle
NOT ~ the input bit was 0 inverting every bit
Left shift << bits move left, zeros fill in multiply by 2ⁿ
Right shift >> bits move right divide by 2ⁿ, discarding the remainder

Truth table

A B A & B A | B A ^ B
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0

A worked example: 60 AND 13

Take A = 60 and B = 13 at 8-bit width.

  • A = 60 = 0011 1100
  • B = 13 = 0000 1101
  • AND compares each column and keeps only the positions where both are 1: 0000 1100
  • That is 12 in decimal, or 0x0C in hexadecimal

Change nothing but the operator and the same pair gives 61 for OR (0011 1101) and 49 for XOR (0011 0001). XOR is the interesting one: apply it twice with the same B and you get your original A back, which is why it shows up in checksums, simple ciphers, and the classic no-temp-variable swap.

Tricks worth memorising

  • Test whether n is even: (n & 1) == 0
  • Test whether n is a power of two: n > 0 && (n & (n - 1)) == 0
  • Clear the lowest set bit: n & (n - 1)
  • Isolate the lowest set bit: n & (-n)
  • Set bit k: n | (1 << k)
  • Clear bit k: n & ~(1 << k)
  • Toggle bit k: n ^ (1 << k)
  • Read bit k: (n >> k) & 1

The power-of-two test is the one I reach for most. A power of two has exactly one bit set, so subtracting 1 flips that bit off and turns every bit below it on, and ANDing the two together must give zero.

Number bases

  • Binary (base 2), prefix 0b. 0b1010 is 10.
  • Octal (base 8), prefix 0o. 0o12 is 10.
  • Decimal (base 10), no prefix.
  • Hexadecimal (base 16), prefix 0x, digits 0 to 9 then A to F. 0xFF is 255.

Hexadecimal dominates in low-level work for one reason: a single hex digit maps to exactly four bits, so you can read a byte off the screen as two independent nibbles without doing any arithmetic.

Two’s complement, and why this calculator avoids it

Signed integers on modern hardware use two’s complement. Positive values are plain binary; a negative value is the positive one with all bits flipped and 1 added. An N-bit signed type therefore covers −2^(N−1) to 2^(N−1) − 1, so 8 bits give −128 to 127 and 32 bits give −2,147,483,648 to 2,147,483,647. Under that scheme ~5 is −6, because flipping 0000 0101 gives 1111 1010.

This calculator reports results as unsigned at the width you pick, so ~5 at 8-bit shows as 250 rather than −6. Both answers describe the identical bit pattern 1111 1010; they differ only in whether the top bit is read as a sign. Right shift is logical here (zeros fill in from the left), which matches the unsigned reading.

Where you actually meet them

  • Networking: a subnet mask is applied with AND, which is exactly what 192.168.1.100 & 255.255.255.0 does.
  • Graphics: packing and unpacking colour channels, alpha blending.
  • Cryptography: AES (Advanced Encryption Standard) and the SHA (Secure Hash Algorithm) family lean on XOR throughout.
  • Permissions: Unix file modes are bit flags, which is why chmod 755 is three octal digits.
  • Compression: bit packing and Huffman coding.

How we build and check this calculator

This calculator runs entirely in your browser, so the numbers you enter stay on your device. The math behind it is written by hand and tested against worked examples and standard references before the page goes live.

SuperGlobalCalculator is independently built and maintained. See how we build and verify our calculators.


Embed This Calculator

Copy the code below and paste it into your website or blog.
The calculator will work directly on your page.