PureDevTools

Bitwise Calculator

Compute AND, OR, XOR, NOT, left shift, right shift — results in decimal, binary, and hex

All processing happens in your browser. No data is sent to any server.

Bitwise Calculator

Input format hint

(or prefix 0x/0b directly)
60 & 13 = 12

Result (signed decimal)

DEC12

Result (unsigned 32-bit)

U3212

Result (hexadecimal)

HEX0xC

Result (32-bit binary, 8-bit groups)

BIN00000000 00000000 00000000 00001100

Common examples

Bitwise truth table (per bit) ▸
ABA AND BA OR BA XOR BNOT A
000001
010111
100110
111100

Bitwise operations are fundamental to systems programming, cryptography, graphics, and performance-critical code — yet they’re often confusing without a visual tool showing what happens at the bit level. This calculator computes bitwise AND, OR, XOR, NOT, left shift, and right shift, displaying results in decimal, binary (32-bit), and hex simultaneously.

The Six Bitwise Operations

All bitwise operations work on the individual bits of their operands, treating each bit independently (except shifts).

AND (&)

A bit is 1 only if both corresponding bits are 1. Used to extract or mask specific bits.

  0011 1100  (60)
& 0000 1101  (13)
-----------
  0000 1100  (12)

Use case: flags & MASK — check if specific flags are set.

OR (|)

A bit is 1 if either bit is 1. Used to set specific bits.

  0011 1100  (60)
| 0000 1101  (13)
-----------
  0011 1101  (61)

Use case: flags | NEW_FLAG — turn on a permission bit.

XOR (^)

A bit is 1 if the bits are different. Used to toggle bits or detect differences.

  0011 1100  (60)
^ 0000 1101  (13)
-----------
  0011 0001  (49)

Use cases:

NOT (~)

Inverts every bit. In 32-bit signed integers, ~n = -(n+1) due to two’s complement.

~ 0000 0000 0000 0000 0000 0000 0011 1100 (60)
= 1111 1111 1111 1111 1111 1111 1100 0011 (-61 signed, 4294967235 unsigned)

Use case: ~MASK — create the complement of a bitmask.

Left Shift (<<)

Shifts all bits left by N positions, filling with zeros on the right. Equivalent to multiplying by 2ᴺ.

60 << 2 = 240
0011 1100 → 1111 0000

Use case: 1 << n — create a mask with only bit n set. Fast power-of-2 multiplication.

Right Shift (>>)

Shifts all bits right by N positions. For signed integers in JS, fills left with the sign bit (arithmetic shift). Equivalent to integer-dividing by 2ᴺ.

60 >> 2 = 15
0011 1100 → 0000 1111

Use case: Extract the high byte: (value >> 8) & 0xFF.

Common Patterns

Extract a Byte from a Multi-Byte Value

const value = 0x12345678;
const byte0 = value & 0xFF;            // 0x78 = 120 (low byte)
const byte1 = (value >> 8) & 0xFF;    // 0x56 = 86
const byte2 = (value >> 16) & 0xFF;   // 0x34 = 52
const byte3 = (value >> 24) & 0xFF;   // 0x12 = 18 (high byte)

Test if a Number Is Even or Odd

// Faster than modulo in tight loops
const isOdd = n & 1;  // true if odd

Round Down to Nearest Power of 2 Boundary

const aligned = value & ~(alignment - 1);
// e.g., align to 16-byte boundary: value & ~15 = value & 0xFFFFFFF0

Swap Two Values Without a Temp Variable

a ^= b;
b ^= a;
a ^= b;
// a and b are now swapped

Bitmask for Feature Flags

const FEATURE_DARK_MODE  = 1 << 0;  // 1
const FEATURE_ANALYTICS  = 1 << 1;  // 2
const FEATURE_BETA       = 1 << 2;  // 4

let flags = FEATURE_DARK_MODE | FEATURE_BETA;  // 5

// Check: is dark mode on?
if (flags & FEATURE_DARK_MODE) { ... }

// Toggle analytics:
flags ^= FEATURE_ANALYTICS;

// Turn off beta:
flags &= ~FEATURE_BETA;

Two’s Complement and the NOT Gotcha

JavaScript’s bitwise operators work on 32-bit signed integers. The NOT operator follows two’s complement arithmetic: ~n = -(n+1).

This has a practical use: ~arr.indexOf(item) !== 0 is equivalent to arr.indexOf(item) !== -1 because ~(-1) = 0 (falsy) and ~(anything_else) ≠ 0 (truthy). Though modern code prefers .includes().

The unsigned right shift >>> (not in this calculator’s primary options but visible in binary output as 32-bit) treats the value as unsigned 32-bit, preventing sign-extension issues.

Practical Use Cases by Domain

DomainOperationExample
NetworkingAND to apply subnet maskIP & subnet_mask
GraphicsBlend channel with mask(color >> 16) & 0xFF
CryptographyMix entropyhash ^= hash >> 13
EmbeddedRead hardware register flagstatus & FLAG_BIT
CompressionPack bits(a & 0xF)
HashingFNV mix stephash ^= byte; hash *= 16777619

Privacy

All calculations run entirely in your browser. No data is sent to any server.

Related Tools

More Encoding & Crypto Tools