Hex Calculator

Convert between hexadecimal, decimal, binary, and octal. Perform hex arithmetic and bitwise operations.

Hex Converter (edit any field)

Hex Arithmetic

Result (Hex)

29

Result (Decimal)

41

How to Use the Hex Calculator

This hex calculator handles the two jobs you actually need a hexadecimal calculator for: converting between hex, decimal, binary, and octal, and doing arithmetic directly on hex numbers. The primary use cases are HTML and CSS color codes (like #FF5733 or #00BFFF), debugging memory addresses, and reading byte values in low-level code. You can use it as a hex to decimal converter, a decimal to hex converter, or a binary to hex converter without switching tools.

  1. Convert from hex: type a hexadecimal value like FF, 2AF, or DEADBEEF in the Hexadecimal field. The decimal, binary, and octal equivalents update as you type. Digits 0-9 and A-F are accepted, and case does not matter (ff equals FF).
  2. Convert from decimal: type a base-10 number in the Decimal field to get its hex representation. This is how you turn an RGB value like 255 into FF, or a byte count like 1024 into 400.
  3. Convert from binary or octal: use the Binary field (0 and 1 only) or the Octal field (0-7 only). Binary 10110100 becomes hex B4, which is far easier to read.
  4. Do hex arithmetic: enter two hex values in Hex A and Hex B, then pick an operation: add, subtract, multiply, divide, AND, OR, or XOR. The result is shown in both hex and decimal. Bitwise operations (AND, OR, XOR) are what you want for masking flags, setting bits, or comparing color channels.

Every calculation runs in your browser, so inputs never leave the page. Whether you are picking a hex color code for a web page or double-checking an assembly-language offset, the math updates instantly.

Hex Formulas and Worked Examples

Hexadecimal is base 16, which means every position is worth 16 times more than the position to its right. The 16 symbols are 0-9 for the first ten values, then A=10, B=11, C=12, D=13, E=14, F=15 for the rest. Everything a hex calculator does boils down to four formulas.

1. Hex to Decimal

Multiply each hex digit by 16 raised to its position (counting from the right, starting at 0), then add the results.

Formula: decimal = sum of (digit × 16^position)

Example: 2AF hex
Positions:  2   A   F
            │   │   └─ 16⁰ = 1
            │   └───── 16¹ = 16
            └───────── 16² = 256

= 2 × 256  +  10 × 16  +  15 × 1
= 512      +  160      +  15
= 687 decimal

Same logic works for any length. FF is 15 × 16 + 15 × 1 = 255. 1000 hex is 1 × 4096 = 4096 decimal. DEADBEEF works the same way, just with more digits.

2. Decimal to Hex

Divide the decimal number by 16 repeatedly, writing down the remainder each time. When the quotient hits 0, read the remainders bottom to top. That string is your hex number.

Example: convert 1000 to hex

1000 ÷ 16 = 62  remainder  8   (8)
  62 ÷ 16 =  3  remainder  14  (E)
   3 ÷ 16 =  0  remainder  3   (3)

Read bottom up: 3 E 8
1000 decimal = 3E8 hex

Check: 3 × 256 + 14 × 16 + 8 × 1 = 768 + 224 + 8 = 1000 ✓

3. Hex Arithmetic (Add and Subtract)

Add or subtract column by column from the right, just like decimal arithmetic, but carry when you hit 16 (not 10). If a column sum is 16 or more, subtract 16 and carry 1 to the next column.

Addition example: 1A + 2F

Column 1 (right): A + F = 10 + 15 = 25
  25 − 16 = 9, carry 1 → write 9
Column 2:          1 + 2 + 1 carry = 4 → write 4

Result: 49 hex = 73 decimal
Check: 26 + 47 = 73 ✓

Subtraction example: 50 − 1B

Column 1: 0 − B. Borrow 1 from column 2.
  16 + 0 − 11 = 5 → write 5
Column 2: (5 − 1) − 1 = 3 → write 3

Result: 35 hex = 53 decimal
Check: 80 − 27 = 53 ✓

4. Hex to Binary (and Back)

This is the shortcut that makes hex useful in computing: every hex digit maps to exactly 4 binary bits. Convert each digit independently and concatenate.

Hex → Binary: convert each digit to 4 bits

0 = 0000    4 = 0100    8 = 1000    C = 1100
1 = 0001    5 = 0101    9 = 1001    D = 1101
2 = 0010    6 = 0110    A = 1010    E = 1110
3 = 0011    7 = 0111    B = 1011    F = 1111

Example: B4 hex
B = 1011
4 = 0100
Concatenate: 10110100 binary

Example: FF hex = 1111 1111 binary = 255 decimal

Binary → Hex: group bits into 4s from the right, convert each group.
11010110 → 1101 0110 → D 6 → D6 hex

Quick Reference Table

The most common conversion values, showing decimal alongside binary, hex, and octal:

DecimalBinaryHexOctal
0000
1111
101010A12
151111F17
16100001020
321000002040
64100000040100
1281000000080200
25511111111FF377
256100000000100400
100011111010003E81750
655351111111111111111FFFF177777

FF is the largest 1-byte value (8 bits). FFFF is the largest 2-byte value (16 bits). FFFFFFFF is the largest 4-byte value, which is where the classic 32-bit unsigned maximum of 4,294,967,295 comes from.

Where Hex Actually Shows Up (and Why It Wins Over Binary)

Hex feels academic until you see how often it appears in real code, browser tools, and device specs. A good hexadecimal calculator is less about schoolwork and more about fluency with the formats you run into in color pickers, debuggers, and hardware labels.

Where You Run Into Hex in the Wild

The same base-16 system shows up under many labels, but the math is identical:

  • HTML and CSS color codes: #FF0000 is pure red, #00FF00 is pure green, #0000FF is pure blue. #FFFFFF is white, #000000 is black, and #808080 is medium gray. Every color you pick in Figma, Photoshop, or a browser dev tool is a hex triple.
  • Memory addresses in debuggers: a crash log showing 0x7FFEE4A3B120 is a hex pointer. gdb, lldb, Xcode, and Visual Studio all display addresses in hex because they line up neatly with byte boundaries.
  • MAC addresses: every network card has one, written as six hex byte pairs like 3C:22:FB:4E:8A:01. That is 48 bits, too long for binary to be readable.
  • File signatures (magic numbers): PNG files start with hex 89 50 4E 47, PDFs with 25 50 44 46 (which spells "%PDF" in ASCII), ZIP archives with 50 4B 03 04. File-type detectors read these hex bytes.
  • Unicode code points: U+1F600 is the grinning-face emoji. The number after "U+" is always hex.
  • Error codes: Windows 0x80070005 (access denied), HTTP traces, and API debug output use hex because it is compact.

Why Hex Instead of Binary

Computers run on binary, but binary is painful for humans. Hex compresses the same information by a factor of 4 because one hex digit equals 4 bits. The same byte in three notations:

NotationLengthExample: Decimal 212
Decimal1-3 digits212
BinaryAlways 8 digits for a byte11010100
HexadecimalAlways 2 digits for a byteD4

Hex is easier to read aloud ("D four") than binary ("one one zero one zero one zero zero"), easier to type without transcription errors, and lines up cleanly with byte boundaries. A 32-bit value is 8 hex digits, a 64-bit value is 16 hex digits, no counting required.

Hex Color Math: Each Pair Is One RGB Channel

Web colors split a hex code into three byte-sized pairs. The first pair is red, the second is green, the third is blue. Each pair ranges from 00 (0, off) to FF (255, maximum). So #FF0000 is rgb(255, 0, 0), pure red. #7F7F7F is rgb(127, 127, 127), medium gray. Mixing channels gives compound colors:

Hex CodeRedGreenBlueColor
#FF000025500Red
#00FF0002550Green
#0000FF00255Blue
#FFFF002552550Yellow
#FF00FF2550255Magenta
#00FFFF0255255Cyan
#FFA5002551650Orange
#808080128128128Gray

8-digit hex codes like #FF000080 add a fourth pair at the end for alpha (opacity). 80 is 128 out of 255, so #FF000080 is red at 50% opacity.

Common Traps and Notation Gotchas

Hex is case-insensitive for the letters, but prefixes, length, and leading zeros trip people up:

  • The 0x prefix in C, Python, JavaScript, and most other languages marks a hex literal. 0x1F equals decimal 31. Without the prefix, most parsers assume decimal. CSS uses # instead of 0x for colors, and assembly often uses a trailing h (1Fh).
  • Case does not change the value. 2a, 2A, and 2a all equal decimal 42. Style guides often prefer uppercase for readability, but parsers accept either.
  • Leading zeros matter for formatting, not value. In color codes, #F00 (3-digit shorthand) expands to #FF0000, and #0F0 becomes #00FF00. In MAC addresses, the pair 0A must keep its leading zero so the byte count stays correct.
  • Hex 10 is not decimal 10. Hex 10 is decimal 16, because the positions are 16¹ and 16⁰. Always check which base you are reading.
  • Bitwise operations are per-bit, not per-digit. F0 AND 0F is 00, not FF, because 11110000 AND 00001111 = 00000000.

The converter and arithmetic panels above handle all of this automatically, so you can paste a color code or a debug offset and get the equivalent representation without worrying about prefixes or casing.

Frequently Asked Questions

Hexadecimal (base 16) is a number system using 16 symbols: 0-9 for the first ten values and A-F for 10 through 15. It is everywhere in computing because each hex digit maps to exactly 4 binary bits, so a byte fits in 2 hex digits instead of 8 binary digits. Common uses include HTML and CSS color codes (#FF5733), memory addresses in debuggers, MAC addresses, Unicode code points (U+1F600), and error codes in Windows and APIs. The byte 11111111 in binary is simply FF in hex, which is far easier to read and transcribe.

Related Calculators