Number Base Conversion: Binary, Hexadecimal, and Decimal

What Is a Number Base?

A number base, or radix, determines how many unique digits a number system uses and how place values work. The decimal system you use daily is base-10, meaning it has 10 digits (0 through 9) and each position represents a power of 10. The number 365 means 3 hundreds, 6 tens, and 5 ones, or (3 x 100) + (6 x 10) + (5 x 1).

This same positional principle applies to every number base. Binary is base-2 with only digits 0 and 1. Octal is base-8 with digits 0 through 7. Hexadecimal is base-16 with digits 0 through 9 plus A through F to represent values 10 through 15. The choice of base is arbitrary; the underlying values are the same regardless of how we write them.

Binary: The Language of Computers

Computers operate in binary because their fundamental building blocks, transistors, have two states: on and off. These map naturally to 1 and 0. Every piece of data in a computer, from text to video to software instructions, is ultimately stored and processed as sequences of binary digits.

In binary, each position represents a power of 2. The binary number 1101 equals (1 x 8) + (1 x 4) + (0 x 2) + (1 x 1) = 13 in decimal. While binary is natural for machines, it is cumbersome for humans because even small numbers require many digits. The decimal number 255, for example, is 11111111 in binary, which is eight digits long. This is why programmers rarely work directly in binary and instead use hexadecimal as a more compact representation.

Hexadecimal: A Programmer's Shorthand

Hexadecimal (hex) is base-16 and serves as a convenient shorthand for binary. Because 16 is a power of 2 (specifically 2 to the 4th), each hex digit maps perfectly to exactly four binary digits. The binary sequence 11111111 becomes FF in hex, which is far easier to read, write, and remember.

Hex is ubiquitous in programming. Web colors are specified in hex (such as #FF5733 for a shade of orange-red). Memory addresses, MAC addresses, Unicode code points, and many debugging outputs use hexadecimal notation. When you see a value prefixed with 0x in code, that signals a hexadecimal number. A CSS color like #5d00ff breaks down to 5D red (93), 00 green (0), and FF blue (255).

Octal: The Historic Middle Ground

Octal (base-8) was popular in early computing when computer architectures used word sizes that were multiples of 3 bits. Each octal digit represents exactly three binary digits, making it a clean intermediate format. The decimal number 255 is 377 in octal.

While octal has largely been replaced by hexadecimal in modern computing, it survives in specific contexts. Unix and Linux file permissions use octal notation: 755 means the owner can read, write, and execute (7), while the group and others can read and execute (5). The C programming language and its descendants use a leading zero to denote octal literals, which occasionally catches beginners off guard when 010 evaluates to 8 rather than 10.

How to Convert Between Bases

Converting from any base to decimal follows the same pattern: multiply each digit by its positional power and sum the results. To convert hex 2A to decimal, calculate (2 x 16) + (10 x 1) = 42. To convert binary 10110 to decimal, calculate (1 x 16) + (0 x 8) + (1 x 4) + (1 x 2) + (0 x 1) = 22.

Converting from decimal to another base uses repeated division. Divide the number by the target base, record the remainder, and repeat with the quotient until it reaches zero. Reading the remainders from bottom to top gives you the result. For example, converting 42 to binary: 42/2=21 r0, 21/2=10 r1, 10/2=5 r0, 5/2=2 r1, 2/2=1 r0, 1/2=0 r1, yielding 101010.

Practical Applications

Understanding number bases is essential for several areas of technology and daily computing:

  • Web development: HTML/CSS colors use hex codes to define precise colors
  • Networking: IPv6 addresses are written in hexadecimal, and subnet masks use binary logic
  • Debugging: Memory dumps and error codes are often displayed in hex
  • File permissions: Unix systems use octal to set read, write, and execute permissions
  • Data encoding: Base64 encoding is used for embedding binary data in text formats like email and JSON

Even if you are not a programmer, encountering hex and binary values is increasingly common in everyday technology. A number base converter handles the translation between decimal, binary, octal, and hex instantly, but understanding the underlying logic demystifies error messages, network settings, and configuration files that would otherwise look like random characters.