Decimal to Hexadecimal: Computer Science Basics

MT
Written by the MyToolDock team
Category: Converter Tools · Published

In this guide

Hexadecimal, or base 16, is a compact way to write binary numbers, which is why it appears in colour codes, memory addresses, error codes and character tables. Converting between decimal and hex is a skill worth having for programmers and designers.

How hexadecimal works

Hex uses sixteen digits: 0 to 9 and then A to F for the values ten to fifteen. Each hex digit stands for exactly four bits, so two hex digits describe one byte. That is why a byte is written 00 to FF, and why hex is much easier to read than a long string of ones and zeros.

Converting decimal to hex

Divide the number by 16 repeatedly and note the remainders, then read the remainders from last to first. For 255: 255 divided by 16 is 15 remainder 15, and 15 divided by 16 is 0 remainder 15. Both remainders are 15, which is F, so 255 is FF. For 300: 300 divided by 16 is 18 remainder 12 (C), 18 divided by 16 is 1 remainder 2, and 1 gives 1, so 300 is 12C.

Converting hex to decimal

Multiply each digit by the power of 16 for its position and add them. 2F is 2 x 16 + 15 = 47. The hex number 1A3 is 1 x 256 + 10 x 16 + 3 = 419.

Where you will see it

CSS colours (#FF8800), memory addresses, MAC addresses, Unicode code points like U+00E9, and byte dumps. Prefixes vary: 0x in many programming languages, # in CSS and U+ for Unicode.

Common slips

Confusing letters and digits (O and 0), forgetting that hex is case-insensitive (ff equals FF), and dropping leading zeros where a fixed width is needed. Very large numbers can exceed the precision of some tools, so use a calculator that handles big integers when needed.

Key Takeaways

Frequently Asked Questions

What is 255 in hex?

FF.

Why do programmers use hex?

It compactly represents binary: each digit is four bits.

Is lowercase hex the same as uppercase?

Yes. ff and FF are the same value.

Free tools mentioned in this guide

Browse every Converter Tools utility, or see all tools.

Recommended Reading

Developer Scratchpad

Copied to clipboard!