GanuLabs

GanuLabs

Informational/Utility

Number Base Converter: Binary, Decimal, and Hex Explained

March 19, 2026

Convert between binary, decimal, and hexadecimal with clear formulas and a quick-reference table.

Why Number Bases Matter

The decimal system (base 10) uses ten digits: 0 through 9. Binary (base 2) uses two digits: 0 and 1. Hexadecimal (base 16) uses sixteen digits: 0 through 9 and A through F. These three number systems are the most practically relevant because they underpin all digital computing — binary is what computers actually use internally; hexadecimal is how programmers represent binary data compactly; decimal is how humans naturally count.

Understanding number base conversion is useful for computer science students, software developers working with memory addresses or color codes, and anyone troubleshooting technical output that appears in hex or binary format. It is also a common topic in school mathematics curricula.

Decimal to Binary Conversion

To convert a decimal number to binary, repeatedly divide by 2 and record the remainders. The binary number is the remainders read in reverse. For the number 13: 13 ÷ 2 = 6 remainder 1; 6 ÷ 2 = 3 remainder 0; 3 ÷ 2 = 1 remainder 1; 1 ÷ 2 = 0 remainder 1. Remainders in reverse: 1101. So 13 in decimal is 1101 in binary.

To verify: in binary, each position represents a power of 2. Reading 1101 right to left: 1×(2⁰) + 0×(2¹) + 1×(2²) + 1×(2³) = 1 + 0 + 4 + 8 = 13. Conversion in both directions uses the positional value of each digit.

Binary to Decimal Conversion

To convert binary to decimal, multiply each binary digit by its positional value (a power of 2) and sum the results. Positions are numbered from right to left starting at 0. For binary 10110: positions from right are 0, 1, 2, 3, 4. Values: 0×1 + 1×2 + 1×4 + 0×8 + 1×16 = 0 + 2 + 4 + 0 + 16 = 22.

The positional values for common binary lengths: 4-bit numbers (nibble) go from 0 to 15; 8-bit numbers (byte) from 0 to 255; 16-bit from 0 to 65,535; 32-bit from 0 to 4,294,967,295. These upper limits define the range of values representable in each data type.

Hexadecimal: The Programmer's Shorthand

Hexadecimal (hex) represents binary data more compactly. One hex digit represents exactly four binary digits (a nibble). This means an 8-bit byte can always be written as exactly two hex digits. For example, the binary byte 11111111 equals FF in hex and 255 in decimal. The compact representation makes hex ideal for memory addresses, color codes, and error codes.

CSS color codes are a common application: #FF5733 is a hex color where FF = red intensity (255), 57 = green intensity (87), and 33 = blue intensity (51). Converting each two-digit hex pair to decimal gives the RGB values. This is also why hex is used in debugging — it represents the binary content of memory in a format short enough to scan visually.

Converting Between Hex and Decimal

Decimal to hex: divide by 16 and record the remainders (0–15, with 10=A through 15=F). For 255: 255 ÷ 16 = 15 remainder 15; 15 ÷ 16 = 0 remainder 15. Remainders in reverse: 15, 15 = FF. For 87: 87 ÷ 16 = 5 remainder 7; 5 ÷ 16 = 0 remainder 5. Remainders in reverse: 5, 7 = 57.

Hex to decimal: multiply each digit by its positional value (a power of 16) and sum. For 2F: F (which is 15) is in the ones position (16⁰ = 1), 2 is in the sixteens position (16¹ = 16). Calculation: (2 × 16) + (15 × 1) = 32 + 15 = 47. So hex 2F equals decimal 47.

Quick Reference Table

Use these benchmark pairs for fast sanity checks.

DecimalBinaryHexadecimal
000
111
810008
101010A
151111F
161000010
25511111111FF

Frequently Asked Questions

What is the easiest way to convert binary to decimal?

Write out the binary number and number each digit position from right to left starting at 0. Multiply each 1-digit by 2 raised to its position number, then sum the results. For 1011: (1×1) + (1×2) + (0×4) + (1×8) = 1 + 2 + 0 + 8 = 11.

Why do programmers use hexadecimal instead of binary?

Because hex is much more compact. Eight binary digits can always be written as two hex digits. Reading a memory address like FF3A is much faster than reading 1111111100111010. Hex and binary convert directly to each other without going through decimal, making hex the preferred human-readable format for binary data.

What does 0xFF mean in programming?

0xFF is hexadecimal notation for the value 255 in decimal, or 11111111 in binary. The 0x prefix indicates that the following digits are in base 16. It is commonly used in programming to represent maximum byte values, bit masks, and color channel intensities.

Related Reading