# Bitwise Calculator

Perform bitwise AND, OR, XOR, NOT, and shift operations on integers. See results in binary, decimal, and hex. Free online bitwise calculator.

## What this calculates

Run AND, OR, XOR, NOT, left shift, and right shift operations on two integers. Results are shown in decimal, binary, and hexadecimal so you can see exactly what happens at the bit level.

## Inputs

- **Operation** — options: AND (&), OR (|), XOR (^), NOT (~) on A, Left Shift (A << B), Right Shift (A >> B) — Select the bitwise operation to perform.
- **Number A** — First integer operand.
- **Number B** — Second integer operand (ignored for NOT).

## Outputs

- **Result (Decimal)** — The result of the operation in decimal.
- **Result (Binary)** — formatted as text — The result of the operation in binary.
- **Result (Hex)** — formatted as text — The result of the operation in hexadecimal.
- **A in Binary** — formatted as text — Number A expressed in binary.
- **B in Binary** — formatted as text — Number B expressed in binary.

## Details

Bitwise operations work directly on the binary representation of integers, processing each bit position independently. They are essential in low-level programming, networking, graphics, and cryptography.

**The Six Operations:**

- **AND (&):** Returns 1 only when both bits are 1. Used for masking specific bits. Example: 12 & 10 = 1100 & 1010 = 1000 = 8.
- **OR (|):** Returns 1 when at least one bit is 1. Used for setting bits. Example: 12 | 10 = 1100 | 1010 = 1110 = 14.
- **XOR (^):** Returns 1 when the bits differ. Used for toggling bits and simple encryption. Example: 12 ^ 10 = 1100 ^ 1010 = 0110 = 6.
- **NOT (~):** Flips every bit. In two's complement, ~n = -(n+1). Example: ~12 = -13.
- **Left Shift (>):** Shifts bits right by n positions. Equivalent to integer division by 2^n. Example: 12 >> 2 = 3.

**Common Uses:**

- **Bit masking:** Extract or modify specific bits in a value
- **Flags:** Store multiple boolean values in a single integer
- **Permissions:** Unix file permissions use bitwise operations
- **Fast math:** Left shift for multiplication, right shift for division by powers of 2
- **Checksums and hashing:** XOR is used in many checksum algorithms

## Frequently Asked Questions

**Q: What is the difference between AND, OR, and XOR?**

A: AND returns 1 only when both bits are 1. OR returns 1 when at least one bit is 1. XOR returns 1 only when the bits are different. For example, with bits 1 and 0: AND gives 0, OR gives 1, and XOR gives 1. With bits 1 and 1: AND gives 1, OR gives 1, and XOR gives 0.

**Q: Why does NOT of a positive number give a negative result?**

A: Computers represent integers using two's complement, where the leftmost bit indicates the sign. NOT flips all bits, including the sign bit. So ~5 (binary 00000101) becomes 11111010, which is -6 in two's complement. The rule is: ~n = -(n + 1).

**Q: How are bit shifts related to multiplication and division?**

A: Left shifting by n positions multiplies by 2^n. Right shifting by n positions divides by 2^n (dropping the remainder). For instance, 5 > 3 = 5 (40 divided by 8). This is much faster than actual multiplication or division in hardware.

**Q: Where are bitwise operations used in real programming?**

A: Bitwise operations are used everywhere: permission flags (Unix chmod), color channel extraction in graphics (RGB masking), network subnet calculations, hardware register manipulation, game state packing, cryptographic algorithms, and data compression. They are also the foundation of how CPUs perform arithmetic internally.

---

Source: https://vastcalc.com/calculators/math/bitwise
Category: Math
Last updated: 2026-04-08
