Hex Calculator

Easily calculate the hex value for any number.
hex
hex

Hexadecimal result
-
Decimal result
-

What are hex numbers and how do you work with them?

If you've ever wondered about those mysterious numbers that start with "0x" in programming or seen color codes like "#FF5733" in web design, you're looking at hexadecimal numbers! Let's dive into what hex numbers are and how to work with them.

What exactly are hexadecimal numbers?

Hexadecimal (or "hex" for short) is a base-16 number system. While we normally use base-10 (decimal) with digits 0-9, hex uses 16 different symbols:

  • Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
  • Letters: A, B, C, D, E, F

Here's what each hex digit represents in decimal:

  • A = 10
  • B = 11
  • C = 12
  • D = 13
  • E = 14
  • F = 15

How do you convert hex to decimal?

Converting from hex to decimal involves understanding positional values. Just like in decimal where each position represents powers of 10, in hex each position represents powers of 16.

The conversion formula

For a hex number, multiply each digit by its corresponding power of 16 and add them up:

Decimal=(dn×16n)+(dn1×16n1)+...+(d1×161)+(d0×160)\text{Decimal} = (d_n \times 16^n) + (d_{n-1} \times 16^{n-1}) + ... + (d_1 \times 16^1) + (d_0 \times 16^0)

Step-by-step example: Converting 3F2 to decimal

Let's convert the hex number 3F2 to decimal:

  1. Identify each digit and its position:

    • 3 is in position 2 (16²)
    • F is in position 1 (16¹)
    • 2 is in position 0 (16⁰)
  2. Convert hex digits to decimal:

    • 3 = 3 (already decimal)
    • F = 15
    • 2 = 2 (already decimal)
  3. Apply the formula:

    • 3×162=3×256=7683 \times 16^2 = 3 \times 256 = 768
    • 15×161=15×16=24015 \times 16^1 = 15 \times 16 = 240
    • 2×160=2×1=22 \times 16^0 = 2 \times 1 = 2
  4. Add them up:

    • 768+240+2=1010768 + 240 + 2 = 1010

So 3F2 (hex) = 1010 (decimal)!

How do you convert decimal to hex?

Converting decimal to hex involves repeatedly dividing by 16 and keeping track of remainders.

Step-by-step example: Converting 255 to hex

  1. Divide 255 by 16:

    • 255÷16=15255 \div 16 = 15 remainder 1515
    • Remainder 15 = F in hex
  2. Divide the quotient (15) by 16:

    • 15÷16=015 \div 16 = 0 remainder 1515
    • Remainder 15 = F in hex
  3. Read the remainders from bottom to top:

    • FF

So 255 (decimal) = FF (hex)!

How do you add hex numbers?

Adding hex numbers works similarly to decimal addition, but you carry over when the sum exceeds 15 (F).

Example: Adding A3 + 2F

    A3
  + 2F
  ----
  1. Add the rightmost digits:

    • 3 + F = 3 + 15 = 18
    • 18 = 16 + 2, so we write 2 and carry 1
  2. Add the next column with carry:

    • A + 2 + 1 = 10 + 2 + 1 = 13
    • 13 = D in hex

Result: A3 + 2F = D2

How do you subtract hex numbers?

Subtraction in hex follows the same borrowing rules as decimal, but you borrow 16 instead of 10.

Example: Subtracting B4 - 27

    B4
  - 27
  ----
  1. Subtract the rightmost digits:

    • 4 - 7: We need to borrow
    • 4 + 16 - 7 = 13 = D
  2. Subtract the next column (remember we borrowed):

    • (B - 1) - 2 = A - 2 = 10 - 2 = 8

Result: B4 - 27 = 8D

How do you multiply hex numbers?

Hex multiplication can be done by converting to decimal, multiplying, then converting back, or by using the traditional multiplication method with hex arithmetic.

Example: Multiplying 2A × 3

Using the direct method:

  1. 3 × A = 3 × 10 = 30 = 1E (hex)
  2. 3 × 2 = 6
  3. Combine: 6 + 1 (carry) = 7

Result: 2A × 3 = 7E

How do you divide hex numbers?

Division in hex is typically done by converting to decimal, dividing, then converting the result back to hex.

Example: Dividing C8 ÷ 4

  1. Convert C8 to decimal:

    • C8 = 12 × 16 + 8 = 192 + 8 = 200
  2. Divide in decimal:

    • 200 ÷ 4 = 50
  3. Convert 50 back to hex:

    • 50 ÷ 16 = 3 remainder 2
    • Result: 32

So C8 ÷ 4 = 32 (hex)

Practical applications

Hex numbers are everywhere in technology:

  • Color codes: #FF0000 represents pure red
  • Memory addresses: 0x7FFF8000 might be a location in computer memory
  • IP addresses: Sometimes displayed in hex format
  • File formats: Many file headers use hex values

Quick reference table

DecimalBinaryHex
000000
100011
200102
300113
401004
501015
601106
701117
810008
910019
101010A
111011B
121100C
131101D
141110E
151111F