Skip to content

How to Convert Decimal to Hexadecimal

Hexadecimal (base 16) uses sixteen symbols - 0-9 and A-F - so one hex digit represents exactly four bits. Converting decimal to hex by hand takes one technique: repeated division by 16. This guide walks through the method, a worked example, and the one-liners that do it in code.

Want the answer instantly? Use the free Decimal to Hex Converter - it shows this working step by step for any number.

The division method

To convert any decimal number to hexadecimal, divide it by 16 repeatedly and track the remainders:

  1. Divide the decimal number by 16.
  2. Write down the remainder (0-15). Remainders 10-15 become the letters A-F.
  3. Divide the quotient by 16 and record the remainder again.
  4. Repeat until the quotient reaches 0.
  5. Read the remainders from last to first - that is your hex number.

Why the method works

Every division by 16 peels off one hex digit, starting from the least significant. The remainder is what doesn't fit into the next power of 16, which is exactly the digit at that position. The same method converts decimal to any base - use 2 for binary or 8 for octal.

A useful mental shortcut: memorize the byte landmarks. 255 is FF, 256 is 100, 4096 is 1000, and 65535 is FFFF. Most hex you meet in practice (colors, memory addresses, byte dumps) is built from these.

Uppercase, lowercase, and the 0x prefix

FF and ff are the same number. CSS colors conventionally use lowercase (#ff5733), while memory addresses and constants often use uppercase (0xFF). The 0x prefix simply marks the value as hexadecimal so 10 (ten) cannot be confused with 0x10 (sixteen).

How 2026 converts from decimal to hexadecimal

Divide by 16 repeatedly and keep each remainder, then read the remainders from bottom to top:

2026÷ 16 =126remainder10 → A
126÷ 16 =7remainder14 → E
7÷ 16 =0remainder7

Result (remainders bottom to top): 7EA

Doing it in code

const decimal = 255;
const hex = decimal.toString(16); // "ff"
const hexUpper = decimal.toString(16).toUpperCase(); // "FF"
const padded = decimal.toString(16).padStart(4, '0'); // "00ff"

Frequently Asked Questions

What is the easiest way to convert decimal to hex?

By hand, divide by 16 repeatedly and read the remainders in reverse. In code, virtually every language has it built in: JavaScript's num.toString(16), Python's hex(num), or C's printf("%x").

How do I convert decimal to hex without a calculator?

Use repeated division by 16. For example, 500 ÷ 16 = 31 remainder 4, then 31 ÷ 16 = 1 remainder 15 (F), then 1 ÷ 16 = 0 remainder 1. Reading upward gives 1F4.

Why do programmers use hexadecimal?

One hex digit equals exactly four bits, so a byte is always two hex digits. That makes hex a compact, human-readable spelling of binary - ideal for memory addresses, color codes, and byte-level debugging.

Related Guides