HomeToolsHex Calculator

Hex Calculator

Perform hexadecimal calculations — Add, Subtract, Multiply, or Divide. Also convert between hex and decimal values.

➕➖✖️➗ Hexadecimal Calculation — Add, Subtract, Multiply, or Divide
Hex Value 1
Operation
Hex Value 2
Result
Converters
Hexadecimal Value
Decimal Result
Decimal Value
Hexadecimal Result

What Is the Hexadecimal Number System?

The hexadecimal (hex) number system is a base-16 positional numeral system. It uses sixteen distinct symbols to represent values: the digits 0 through 9 represent values zero to nine, and the letters A through F (case-insensitive) represent values ten through fifteen.

Hex DigitDecimal ValueBinary (4-bit)

Because each hexadecimal digit maps to exactly 4 binary bits (a "nibble"), hex provides a compact, human-readable representation of binary data. Two hex digits represent one byte (8 bits), so FF = 11111111 = 255. This direct mapping is why hexadecimal is the preferred notation in computing for memory addresses, color codes, MAC addresses, error codes, and low-level programming.

For comparison, the number 255 is written as:

Binary (base 2): 1111 1111 — 8 digits Octal (base 8): 377 — 3 digits Decimal (base 10): 255 — 3 digits Hex (base 16): FF — 2 digits

Hex is far more compact than binary and aligns perfectly with byte boundaries, making it indispensable in systems programming, networking, and digital design.

Hex to Decimal Conversion

To convert a hexadecimal number to decimal, multiply each hex digit by 16 raised to the power of its position (starting from 0 on the right), then sum all the products. This is called positional notation expansion.

Formula

Hex number: dₙ dₙ₋₁ ... d₂ d₁ d₀ Decimal = dₙ × 16ⁿ + dₙ₋₁ × 16ⁿ⁻¹ + ... + d₂ × 16² + d₁ × 16¹ + d₀ × 16⁰

Where each dᵢ is the decimal equivalent of the hex digit at position i.

Example 1: Convert 3B to Decimal

3B₁₆ Position 1: 3 × 16¹ = 3 × 16 = 48 Position 0: B × 16⁰ = 11 × 1 = 11 Decimal = 48 + 11 = 59 ∴ 3B₁₆ = 59₁₀

Example 2: Convert 2AF to Decimal

2AF₁₆ Position 2: 2 × 16² = 2 × 256 = 512 Position 1: A × 16¹ = 10 × 16 = 160 Position 0: F × 16⁰ = 15 × 1 = 15 Decimal = 512 + 160 + 15 = 687 ∴ 2AF₁₆ = 687₁₀

Example 3: Convert FFFF to Decimal

FFFF₁₆ F × 16³ = 15 × 4096 = 61,440 F × 16² = 15 × 256 = 3,840 F × 16¹ = 15 × 16 = 240 F × 16⁰ = 15 × 1 = 15 Decimal = 61,440 + 3,840 + 240 + 15 = 65,535 ∴ FFFF₁₆ = 65,535₁₀ (max value of a 16-bit unsigned integer)

Powers of 16 Reference

PowerValueCommon Name
16⁰1
16¹16
16²2561 byte max + 1
16³4,096
16⁴65,5362-byte max + 1
16⁵1,048,5761 MB
16⁶16,777,21616 MB
16⁷268,435,456256 MB
16⁸4,294,967,2964-byte max + 1 (4 GB)

Decimal to Hex Conversion

To convert a decimal number to hexadecimal, use the repeated division by 16 method:

  1. Divide the decimal number by 16.
  2. Record the remainder (0–15). If the remainder is 10–15, write it as A–F.
  3. Replace the dividend with the quotient.
  4. Repeat until the quotient becomes 0.
  5. Read the remainders from bottom to top — that is your hex number.

Example 1: Convert 255 to Hex

255 ÷ 16 = 15 remainder 15 → F 15 ÷ 16 = 0 remainder 15 → F Read remainders bottom-up: FF ∴ 255₁₀ = FF₁₆

Example 2: Convert 1000 to Hex

1000 ÷ 16 = 62 remainder 8 → 8 62 ÷ 16 = 3 remainder 14 → E 3 ÷ 16 = 0 remainder 3 → 3 Read remainders bottom-up: 3E8 ∴ 1000₁₀ = 3E8₁₆

Example 3: Convert 43,981 to Hex

43981 ÷ 16 = 2748 remainder 13 → D 2748 ÷ 16 = 171 remainder 12 → C 171 ÷ 16 = 10 remainder 11 → B 10 ÷ 16 = 0 remainder 10 → A Read remainders bottom-up: ABCD ∴ 43,981₁₀ = ABCD₁₆

Hex Addition

Hexadecimal addition works exactly like decimal addition, except that a carry occurs when the column sum reaches 16 or more (instead of 10 in decimal). Here are the key rules:

  1. Add corresponding digits from right to left.
  2. Convert each hex digit to its decimal equivalent (A=10, B=11, ..., F=15), add them, and include any carry from the previous column.
  3. If the sum is less than 16, write the hex digit directly.
  4. If the sum is 16 or greater, subtract 16, write the remainder as a hex digit, and carry 1 to the next column.

Example 1: 1F + 2A

1 F + 2 A ───── Column 0 (rightmost): F + A = 15 + 10 = 25 25 ≥ 16 → 25 − 16 = 9, carry 1 Write: 9 Column 1: 1 + 2 + 1 (carry) = 4 4 < 16 → write 4 ───── 4 9 ∴ 1F₁₆ + 2A₁₆ = 49₁₆ = 73₁₀

Example 2: 7C5 + 3BA

7 C 5 + 3 B A ─────── Column 0: 5 + A = 5 + 10 = 15 = F 15 < 16 → write F, carry 0 Column 1: C + B = 12 + 11 = 23 23 ≥ 16 → 23 − 16 = 7, carry 1 Write: 7 Column 2: 7 + 3 + 1 (carry) = 11 = B 11 < 16 → write B ─────── B 7 F ∴ 7C5₁₆ + 3BA₁₆ = B7F₁₆ = 2,943₁₀

Example 3: FFF + 1

F F F + 1 ─────── Column 0: F + 1 = 16 → write 0, carry 1 Column 1: F + 0 + 1 = 16 → write 0, carry 1 Column 2: F + 0 + 1 = 16 → write 0, carry 1 Column 3: 0 + 0 + 1 = 1 → write 1 ─────── 1 0 0 0 ∴ FFF₁₆ + 1₁₆ = 1000₁₆ = 4,096₁₀

This example shows how hex carries cascade through all columns, similar to 999 + 1 = 1000 in decimal.

Hex Subtraction

Hexadecimal subtraction follows the same principle as decimal subtraction, except borrowing adds 16 (instead of 10 in decimal). Here are the key rules:

  1. Subtract corresponding digits from right to left.
  2. If the top digit is greater than or equal to the bottom digit, subtract normally and write the hex result.
  3. If the top digit is smaller than the bottom digit, borrow 16 from the next column (reducing it by 1), then subtract.
  4. Convert the decimal result back to a hex digit.

Example 1: 3A − 1F

3 A − 1 F ───── Column 0: A − F = 10 − 15: can't subtract, need to borrow Borrow 16 from column 1: 10 + 16 = 26 26 − 15 = 11 = B Write: B Column 1: 3 − 1 − 1 (borrow) = 1 Write: 1 ───── 1 B ∴ 3A₁₆ − 1F₁₆ = 1B₁₆ = 27₁₀

Example 2: A3C − 5D7

A 3 C − 5 D 7 ─────── Column 0: C − 7 = 12 − 7 = 5 Write: 5, no borrow Column 1: 3 − D = 3 − 13: can't subtract, borrow 3 + 16 = 19; 19 − 13 = 6 Write: 6 Column 2: A − 5 − 1 (borrow) = 10 − 5 − 1 = 4 Write: 4 ─────── 4 6 5 ∴ A3C₁₆ − 5D7₁₆ = 465₁₆ = 1,125₁₀

Example 3: 1000 − 1

1 0 0 0 − 1 ───────── Column 0: 0 − 1: borrow → 0 + 16 − 1 = 15 = F Column 1: 0 − 0 − 1 (borrow): borrow → 0 + 16 − 1 = 15 = F Column 2: 0 − 0 − 1 (borrow): borrow → 0 + 16 − 1 = 15 = F Column 3: 1 − 0 − 1 (borrow) = 0 ───────── F F F ∴ 1000₁₆ − 1₁₆ = FFF₁₆ = 4,095₁₀

This is the inverse of the addition example above — cascading borrows fill every column with F, just as 1000 − 1 = 999 in decimal.

Hex Multiplication

Hex multiplication uses the same long multiplication technique as decimal. The key difference is that you multiply hex digits, convert the products to hex, and carry values in multiples of 16.

  1. Multiply each digit of the bottom number by each digit of the top number (using decimal values).
  2. Convert each product back to hex. If the product ≥ 16, write the remainder and carry the quotient.
  3. Shift each partial product one position to the left (multiply by 16) for each subsequent digit.
  4. Add all partial products together using hex addition.

Example 1: A × 3 (Single-digit)

A × 3 A = 10 in decimal 10 × 3 = 30 Convert 30 to hex: 30 ÷ 16 = 1 remainder 14 (E) 1 ÷ 16 = 0 remainder 1 Read bottom-up: 1E ∴ A₁₆ × 3₁₆ = 1E₁₆ = 30₁₀

Example 2: 1F × 3

1 F × 3 ───── Step 1: F × 3 = 15 × 3 = 45 45 ÷ 16 = 2 remainder 13 (D) Write D, carry 2 Step 2: 1 × 3 = 3, plus carry 2 = 5 Write 5 ───── 5 D ∴ 1F₁₆ × 3₁₆ = 5D₁₆ = 93₁₀

Example 3: 2F × 15 (Multi-digit × Multi-digit)

2 F × 1 5 ─────── Partial product 1 (× 5): F × 5 = 15 × 5 = 75 → 75 ÷ 16 = 4 rem 11(B) → write B, carry 4 2 × 5 = 10 + 4 = 14 (E) → write E Partial product 1: EB Partial product 2 (× 1, shifted left): F × 1 = 15 → write F 2 × 1 = 2 → write 2 Partial product 2: 2F0 (shifted one position left) Add partial products: E B + 2 F 0 ─────── Column 0: B = B Column 1: E + F = 14 + 15 = 29 → 29 − 16 = 13(D), carry 1 Column 2: 0 + 2 + 1 = 3 3 D B ∴ 2F₁₆ × 15₁₆ = 3DB₁₆ = 987₁₀ Verify: 47₁₀ × 21₁₀ = 987₁₀ ✓

Hex Division

Hex division can be performed using long division in hex, or more practically by converting to decimal, dividing, and converting back. For integer division, the result includes both a quotient and a remainder.

Method: Convert → Divide → Convert Back

  1. Convert both the dividend and divisor from hex to decimal.
  2. Perform integer division in decimal to find the quotient and remainder.
  3. Convert the quotient and remainder back to hex.

Example 1: FF ÷ 10

Step 1: Convert to decimal FF₁₆ = 255₁₀ 10₁₆ = 16₁₀ Step 2: Integer division 255 ÷ 16 = 15 remainder 15 Step 3: Convert back to hex Quotient: 15₁₀ = F₁₆ Remainder: 15₁₀ = F₁₆ ∴ FF₁₆ ÷ 10₁₆ = F₁₆ remainder F₁₆

Example 2: 3E8 ÷ A

Step 1: Convert to decimal 3E8₁₆ = 1000₁₀ A₁₆ = 10₁₀ Step 2: Integer division 1000 ÷ 10 = 100 remainder 0 Step 3: Convert back to hex Quotient: 100₁₀ = 64₁₆ Remainder: 0₁₀ = 0₁₆ ∴ 3E8₁₆ ÷ A₁₆ = 64₁₆ remainder 0₁₆

Example 3: ABCD ÷ 1F

Step 1: Convert to decimal ABCD₁₆ = 43,981₁₀ 1F₁₆ = 31₁₀ Step 2: Integer division 43,981 ÷ 31 = 1,418 remainder 23 Step 3: Convert back to hex Quotient: 1,418₁₀ = 58A₁₆ Remainder: 23₁₀ = 17₁₆ ∴ ABCD₁₆ ÷ 1F₁₆ = 58A₁₆ remainder 17₁₆ Verify: 58A₁₆ × 1F₁₆ + 17₁₆ = 1418 × 31 + 23 = 43,958 + 23 = 43,981 = ABCD₁₆ ✓

Common Hexadecimal Values in Computing

These are the most frequently encountered hex values in software development, networking, and systems programming:

Hex ValueDecimalSignificance
0x000Null byte, string terminator in C
0x0A10Line feed (LF) — newline character
0x0D13Carriage return (CR)
0x2032Space character (ASCII)
0x4165Letter 'A' in ASCII
0x6197Letter 'a' in ASCII
0x7F127Max 7-bit signed integer (DEL character)
0xFF255Max 1-byte unsigned value (8-bit)
0x100256One byte overflow boundary
0x3E81,000One thousand
0xFFF4,095Max 12-bit unsigned value
0xFFFF65,535Max 2-byte unsigned value (16-bit)
0xFFFFFF16,777,215Max 24-bit value (white color #FFFFFF)
0xFFFFFFFF4,294,967,295Max 4-byte unsigned value (32-bit)
0xDEADBEEF3,735,928,559Common debug/magic number
0xCAFEBABE3,405,691,582Java class file magic number

How Hex Color Codes Work

In web development and design, colors are specified using 6-digit hex codes in the format #RRGGBB. Each pair of hex digits represents one color channel:

Example: Decode #FF5733

#FF5733 Red: FF₁₆ = 255₁₀ (maximum red) Green: 57₁₆ = 87₁₀ (moderate green) Blue: 33₁₆ = 51₁₀ (low blue) CSS equivalent: rgb(255, 87, 51) Color: A vibrant orange-red

Common Color Codes

Hex CodeRGB DecimalColor Name
#000000rgb(0, 0, 0)Black
#FFFFFFrgb(255, 255, 255)White
#FF0000rgb(255, 0, 0)Red
#00FF00rgb(0, 255, 0)Green (Lime)
#0000FFrgb(0, 0, 255)Blue
#FFFF00rgb(255, 255, 0)Yellow
#FF00FFrgb(255, 0, 255)Magenta
#00FFFFrgb(0, 255, 255)Cyan
#808080rgb(128, 128, 128)Gray
#FFA500rgb(255, 165, 0)Orange

Shorthand notation uses 3 hex digits where each digit is doubled: #F60 = #FF6600. CSS also supports an 8-digit format #RRGGBBAA where the last pair represents alpha (opacity).

Signed Hexadecimal & Two's Complement

In computing, negative numbers are typically represented using two's complement. The interpretation of a hex value depends on the bit-width of the system:

HexUnsigned (8-bit)Signed (8-bit)
0000
011+1
7F127+127 (max positive)
80128−128 (min negative)
FE254−2
FF255−1

How to Find the Negative of a Hex Number (Two's Complement)

  1. Invert all bits — flip every 0 to 1 and every 1 to 0 (this is the "one's complement").
  2. Add 1 to the result.
Example: Find two's complement of 3A (8-bit) Step 1: Convert to binary 3A₁₆ = 0011 1010₂ Step 2: Invert all bits (one's complement) 0011 1010 → 1100 0101 = C5₁₆ Step 3: Add 1 C5 + 1 = C6₁₆ ∴ −3A₁₆ is represented as C6₁₆ in 8-bit signed format. Verify: 3A + C6 = 100₁₆ (overflow discarded) = 00₁₆ ✓

Hexadecimal in Programming Languages

Most programming languages support hex literals with a prefix. Here's how to use hex values across popular languages:

LanguageHex Literal SyntaxExample
Python0x prefixx = 0xFF → 255
JavaScript0x prefixlet x = 0xFF; → 255
C / C++0x prefixint x = 0xFF; → 255
Java0x prefixint x = 0xFF; → 255
C#0x prefixint x = 0xFF; → 255
Rust0x prefixlet x = 0xFF; → 255
Go0x prefixx := 0xFF → 255
Swift0x prefixlet x = 0xFF → 255
PHP0x prefix$x = 0xFF; → 255
Assembly0x or h suffixMOV AX, 0FFh
CSS / HTML# prefix#FF5733

Conversion Functions by Language

Python: hex(255) → '0xff' # Decimal to hex int('FF', 16) → 255 # Hex to decimal JavaScript: (255).toString(16) → 'ff' # Decimal to hex parseInt('FF', 16) → 255 # Hex to decimal C (printf / scanf): printf("%X", 255) → "FF" # Print decimal as hex sscanf("FF", "%x", &n) # Parse hex string Java: Integer.toHexString(255) → "ff" # Decimal to hex Integer.parseInt("FF", 16) → 255 # Hex to decimal

Where Hexadecimal Is Used in the Real World

Hexadecimal is ubiquitous in computing and technology. Here are its most important applications:

1. Memory Addresses

When debugging software or analyzing crash dumps, memory addresses are displayed in hex. A 64-bit address like 0x7FFE3C2A1000 is far more readable than its 48-digit binary equivalent.

2. HTML / CSS Color Codes

Web colors use the #RRGGBB format. For example, #1E90FF is "Dodger Blue." Each pair encodes a color channel from 0 (none) to FF (full intensity).

3. MAC Addresses

Every network interface has a unique 48-bit MAC address written in hex: 00:1A:2B:3C:4D:5E. Each pair is one byte.

4. IPv6 Addresses

IPv6 addresses use eight groups of four hex digits separated by colons: 2001:0db8:85a3:0000:0000:8a2e:0370:7334.

5. Unicode & Character Encoding

Unicode code points are written in hex: U+0041 = 'A', U+1F600 = '😀'. UTF-8 byte sequences are also expressed in hex.

6. File Formats & Magic Numbers

Files start with "magic bytes" to identify their format. For example, PDF files begin with 25 50 44 46 (%PDF in ASCII). Hex editors display and edit raw file bytes.

7. Assembly Language & Machine Code

CPU opcodes, register values, and instruction encodings are written in hex. The x86 instruction B8 FF 00 00 00 means "move 255 into EAX."

8. Cryptographic Hashes

Hash functions like MD5, SHA-1, and SHA-256 output digests as hex strings. For example, the SHA-256 of "hello" starts with 2cf24dba5fb0....

Hexadecimal Multiplication Table

Each cell shows the product of the row header × column header in hexadecimal. This table is useful for manual hex multiplication and verification. For example, to find C × B, look at row C, column B → 84 (which is 132₁₀).

Frequently Asked Questions (FAQ)

What is a hex calculator?

A hex calculator is a tool that performs arithmetic operations (addition, subtraction, multiplication, division) directly on hexadecimal numbers. It also converts between hexadecimal and decimal number systems, showing step-by-step solutions.

How do I add two hex numbers?

Add corresponding digits from right to left, converting A–F to 10–15. If a column sum is 16 or more, subtract 16 and carry 1 to the next column. For example, B + 7 = 18, so write 2 (18 − 16) and carry 1.

How do I subtract hex numbers?

Subtract digits right to left. If the top digit is smaller than the bottom digit, borrow 16 from the next column and add it to the current digit, then subtract. For example, to compute 3 − A: borrow to get 19 − 10 = 9.

What is the difference between hex and decimal?

Decimal is base-10 (digits 0–9) and is the standard human counting system. Hexadecimal is base-16 (digits 0–F) and is used in computing because it maps perfectly to binary: each hex digit = 4 bits. The number 255 in decimal is FF in hex and 11111111 in binary.

Why do computers use hexadecimal instead of decimal?

Computers operate in binary (base-2), but binary strings are very long and error-prone for humans. Hex provides a 4:1 compression ratio — one hex digit replaces four binary digits — while maintaining perfect alignment with byte (8-bit) and word (16/32/64-bit) boundaries. This makes hex ideal for representing memory, colors, and machine instructions.

What does the 0x prefix mean?

The 0x prefix is a convention in most programming languages (C, C++, Java, JavaScript, Python, etc.) to indicate that the following number is hexadecimal. For example, 0xFF means hex FF (decimal 255). Without the prefix, FF might be interpreted as a variable name.

What is the maximum value of a hex byte?

A single byte (8 bits) has a maximum value of FF in hex, which equals 255 in decimal. For signed 8-bit integers using two's complement, the range is 80 (−128) to 7F (+127).

How do hex color codes work?

Hex color codes use the format #RRGGBB, where RR, GG, and BB are hex values (00–FF) for Red, Green, and Blue channels. #000000 is black, #FFFFFF is white, and #FF0000 is pure red. Each channel has 256 possible values (0–255), giving 16.7 million possible colors.

Can hex numbers be negative?

Hexadecimal itself does not define negative numbers, but in computing, negative values are represented using two's complement. For example, in an 8-bit signed system, FF represents −1, and 80 represents −128. The interpretation depends on whether the system treats the value as signed or unsigned.

How do I convert a large hex number to decimal?

For large hex numbers, use positional notation: multiply each digit by its power of 16 and sum the results. For very large values, use our calculator above or programming functions like Python's int('DEADBEEF', 16) which returns 3,735,928,559.

Related Conversion Tools

Explore our other free number conversion tools:

Learn More

Number Conversion