TSE.
MathematicsFinanceHealthPhysicsEngineeringBrowse all

Computer Science · Digital & Computing

Hexadecimal ↔ Decimal Converter

Convert hexadecimal (base-16) to decimal (base-10) and back in both directions.

Calculator

Advertisement

Formula

Hex to decimal: each hex digit h_i (0–F) is multiplied by 16 raised to its position i from the right. Decimal to hex: repeatedly divide by 16 and collect remainders (0–9, A–F).

Source: Knuth, D. E. — The Art of Computer Programming, Vol. 2. Addison-Wesley, 1997.

How it works

Hexadecimal uses 16 symbols: 0–9 and A–F (where A=10, B=11, C=12, D=13, E=14, F=15). Each hex digit represents exactly 4 binary bits, making hex a compact representation of binary data widely used in programming, memory addresses, and color codes.

Hex to decimal: multiply each digit by 16 raised to its position from the right and sum. Decimal to hex: repeatedly divide by 16, collecting remainders as hex digits read bottom-to-top.

Worked example

Hex → Decimal: Convert 1F4.
1×16² + F×16¹ + 4×16⁰ = 256 + 240 + 4 = 500

Decimal → Hex: Convert 500.
500÷16=31 r4, 31÷16=1 r15(F), 1÷16=0 r1 → read upward: 1F4

Limitations & notes

Handles non-negative integers only. Numbers above 53 bits may lose precision. Input letters must be A–F (case-insensitive). Does not support hex fractions or negative numbers.

Frequently asked questions

What are the hex digits A–F?

A=10, B=11, C=12, D=13, E=14, F=15. These extend the decimal digits 0–9 to give 16 unique symbols for base-16.

Why is hexadecimal used in computing?

Each hex digit maps exactly to 4 binary bits, so 2 hex digits represent a byte. This makes hex much more compact and readable than binary for memory addresses, color codes, and machine code.

How do I convert hex FF to decimal?

F×16 + F×1 = 15×16 + 15 = 240 + 15 = 255. This is why #FF in RGB color codes means maximum intensity (255).

Is hex conversion lossless?

Yes, for non-negative integers within JavaScript's 53-bit safe integer range. Every integer maps exactly to one hex representation.

How does hex relate to binary?

Every hex digit = exactly 4 binary bits. Hex 1F4 = binary 0001 1111 0100. This direct mapping makes hex a shorthand for binary in all computing contexts.

Last updated: 2025-01-15 · Formula verified against primary sources.