Bitwise Calculator & Binary Sandbox

Compute bitwise boolean logic (AND, OR, XOR, NOT) and bit shifts (<<, >>, >>>) in real-time. Toggle individual bits, inspect hex and binary forms, and understand signed Two's Complement arithmetic.

Dec: 12Hex: 0xCBin: 00001100
8-Bit Clickable Toggle:
Dec: 5Hex: 0x5Bin: 00000101
&

Bitwise AND

12 & 5

1 if both bits are 1, else 0

Decimal:4
Hexadecimal:0x4
8-bit Binary:00000100
|

Bitwise OR

12 | 5

1 if either bit is 1, else 0

Decimal:13
Hexadecimal:0xD
8-bit Binary:00001101
^

Bitwise XOR

12 ^ 5

1 if bits are different, else 0

Decimal:9
Hexadecimal:0x9
8-bit Binary:00001001
~

Bitwise NOT A

~12

Inverts every bit of operand A (Two's complement)

Decimal:-13
Hexadecimal:0xFFFFFFF3
8-bit Binary:11110011
~

Bitwise NOT B

~5

Inverts every bit of operand B

Decimal:-6
Hexadecimal:0xFFFFFFFA
8-bit Binary:11111010
<<

Left Shift (A << B)

12 << 5

Shifts bits of A left by B positions (Multiplies by 2^B)

Decimal:384
Hexadecimal:0x180
8-bit Binary:10000000
>>

Sign-Propagating Right Shift (A >> B)

12 >> 5

Shifts bits of A right, preserving sign bit

Decimal:0
Hexadecimal:0x0
8-bit Binary:00000000
>>>

Zero-Fill Right Shift (A >>> B)

12 >>> 5

Shifts bits right, pushing 0s in from the left

Decimal:0
Hexadecimal:0x0
8-bit Binary:00000000

Understanding Bitwise Operations in Modern Computing

Every digital computer operates on binary digits (bits)—sequences of 0s and 1s representing electric voltage states (low and high). While standard arithmetic operators (+, -, *, /) treat numbers as whole values, bitwise operators manipulate numbers at the granular level of individual bits. They are the fastest operations a CPU can execute, requiring just one clock cycle on standard ALU (Arithmetic Logic Unit) pipelines.

Core Bitwise Operators Reference Table

OperatorOperation NameExample (A=12, B=5)ResultLogic Rule
&Bitwise AND12 & 5 (00001100 & 00000101)4 (00000100)1 only if both bits are 1; otherwise 0.
|Bitwise OR12 | 5 (00001100 | 00000101)13 (00001101)1 if either bit is 1; 0 only if both are 0.
^Bitwise XOR12 ^ 5 (00001100 ^ 00000101)9 (00001001)1 if bits are different; 0 if bits are identical.
~Bitwise NOT (Unary)~12-13Inverts all bits. Follows formula -(x + 1).
<<Left Shift12 << 248Shifts bits left by B positions; fills with 0s. Equivalent to A * 2^B.
>>Sign-propagating Right Shift12 >> 23Shifts bits right; preserves sign bit on left. Equivalent to floor(A / 2^B).
>>>Zero-fill Right Shift-12 >>> 21073741821Shifts bits right and fills leftmost bits with 0s, coercing negative numbers to positive 32-bit uints.

Why Does ~12 Result in -13? (Two's Complement Explained)

In standard computer architectures (x86, ARM, RISC-V), negative integers are represented using Two's Complement. In an 8-bit signed integer space:

  • 12 in binary is 0000 1100.
  • Bitwise NOT (~) flips every bit: 0000 1100 becomes 1111 0011.
  • Because the leading bit (sign bit) is 1, the processor treats this as a negative number.
  • To determine the magnitude of a negative number in two's complement: invert the bits and add 1. Inverting 1111 0011 gives 0000 1100 (12). Adding 1 yields 0000 1101 (13). Hence, the value is -13.

Real-World Applications in Production Systems

1. Access Control & Permission Bitmasks

Unix systems store permissions using bit flags: Read (4 = 0b100), Write (2 = 0b010), and Execute (1 = 0b001). A full permission set is simply 4 | 2 | 1 = 7. Checking permissions requires a single instruction: (userPerms & READ_FLAG) !== 0.

2. 32-bit Color Packing (RGBA)

Game graphics pack four 8-bit color channels (Red, Green, Blue, Alpha) into a single 32-bit integer: const color = (r << 24) | (g << 16) | (b << 8) | a. Extracting red later is as simple as (color >>> 24) & 0xFF.

3. Cryptography & Hashing Algorithms

Algorithms such as SHA-256, MD5, AES, and ChaCha20 rely heavily on bitwise XOR (^) and circular bit shifts (rotate left/right) to introduce non-linear diffusion, preventing statistical pattern analysis.

Frequently Asked Questions (FAQ)

What is a bitwise calculator?

A bitwise calculator is a developer utility that performs boolean operations directly on the individual binary bits of numbers. It computes fundamental computer architecture operations including AND (&), OR (|), XOR (^), NOT (~), and bit shifts (<<, >>, >>>).

Why does bitwise NOT (~12) equal -13 in JavaScript and modern programming languages?

Modern computer processors and programming languages store signed integers using Two's Complement binary representation. The formula for bitwise NOT is ~x = -(x + 1). Applying NOT to 12 (00001100 in 8-bit) inverts all bits to 11110011, which represents -13 in signed two's complement.

What is the difference between arithmetic right shift (>>) and logical right shift (>>>)?

Arithmetic right shift (>>) preserves the sign bit (the leftmost bit) by filling empty positions on the left with copies of the original sign bit (0 for positive, 1 for negative). Logical or zero-fill right shift (>>>) always pushes 0 into the leftmost positions, treating numbers as unsigned 32-bit integers.

How are bitwise operators used in real-world software engineering?

Bitwise operations are extensively used in high-performance computing, game engines, embedded systems, networking, and graphics. Common applications include permission bitmasks (such as UNIX chmod 755), packing multiple boolean flags or RGBA color channels into a single 32-bit integer, and fast multiplication/division by powers of two.

What number formats does this online bitwise calculator support?

This calculator accepts standard decimal integers (e.g., 12, 255), hexadecimal values prefixed with 0x (e.g., 0xFF, 0x1A), and binary strings prefixed with 0b (e.g., 0b1100, 0b1010). Outputs are automatically rendered across Decimal, Hexadecimal, and 8-bit/32-bit Binary formats.

Explore Related Tools

Hand-picked utilities and calculators related to this tool.

Developer Tools