Back to Blog
math2026-07-105 min

Number Base Converter: Binary, Octal, Decimal, Hexadecimal

Learn number base conversion methods for binary, octal, decimal, and hexadecimal systems. Understand computer arithmetic, hex colors, ASCII encoding, and positional notation.


Number Base Converter: Binary, Octal, Decimal, Hexadecimal

Number base conversion is a fundamental concept in mathematics and computer science. Understanding how to convert between different number systems is essential for programming, digital electronics, data representation, and many other technical disciplines. This guide explores the mathematics behind base conversion and the practical applications of each number system.

My old roommate, a self-taught developer, once spent three hours debugging a CSS color issue because he'd misread a hex code. "#F00" isn't orange—it's pure red. That mix-up taught him more about base-16 than any textbook ever could. Sometimes the best lessons come from the dumbest mistakes.


Matrix movie still

Photo by Markus Spiske on Unsplash

Historical Origins of Number Systems

The decimal (base-10) system that dominates modern human civilization likely originated from counting on fingers. Evidence of base-10 systems dates back to ancient Egypt and Mesopotamia. However, other bases have played important historical roles:

Base-20 (Vigesimal): Used by the Maya civilization and still evident in French numbering (quatre-vingts = four twenties) and Danish/Greenlandic counting systems.

Base-60 (Sexagesimal): Developed by the Sumerians around 3000 BCE, this system survives in our measurement of time (60 seconds, 60 minutes) and angles (360 degrees).

Base-12 (Duodecimal): Evidence suggests base-12 counting systems were used in ancient trade, with remnants in the English word "dozen" and the 12 inches in a foot.

Positional Notation Mathematics

All positional number systems share the same fundamental structure. A number in base b is represented as:

Value = Σ(d_i × b^i)

Where d_i represents the digit at position i, and b is the base. For example, the decimal number 473 represents:

4×10² + 7×10¹ + 3×10⁰ = 400 + 70 + 3 = 473

This same principle applies regardless of the base being used. The beauty of positional notation is that it's one trick—repeated everywhere.

Binary (Base-2)

Binary is the foundation of all digital computing. Every operation performed by a computer ultimately reduces to manipulations of binary digits (bits). The binary system uses only two digits: 0 and 1.

Decimal to Binary Conversion:
To convert a decimal number to binary, repeatedly divide by 2 and record the remainders:

Example: Convert 45 to binary

  • 45 ÷ 2 = 22 remainder 1

  • 22 ÷ 2 = 11 remainder 0

  • 11 ÷ 2 = 5 remainder 1

  • 5 ÷ 2 = 2 remainder 1

  • 2 ÷ 2 = 1 remainder 0

  • 1 ÷ 2 = 0 remainder 1


Reading remainders from bottom to top: 101101

Binary to Decimal Conversion:
Multiply each binary digit by 2 raised to its position power and sum the results:

1×2⁵ + 0×2⁴ + 1×2³ + 1×2² + 0×2¹ + 1×2⁰ = 32 + 8 + 4 + 1 = 45

Octal (Base-8)

Octal provides a more compact representation than binary while maintaining easy conversion to and from binary. Each octal digit represents exactly three binary digits, making octal useful for grouping binary data.

Binary to Octal Conversion:
Group binary digits into sets of three (starting from the right) and convert each group to its octal equivalent:

  • 000 = 0

  • 001 = 1

  • 010 = 2

  • 011 = 3

  • 100 = 4

  • 101 = 5

  • 110 = 6

  • 111 = 7


Historical uses of octal include Unix file permissions and early computer systems with word sizes that were multiples of three.

Hexadecimal (Base-16)

Hexadecimal is widely used in computing because it provides a compact representation of binary data with each hex digit representing exactly four binary digits.

Hexadecimal Digits:
0-9 represent values 0-9, and A-F represent values 10-15.

Applications of Hexadecimal:

Color Representation (RGB):
Colors in web design are commonly expressed as 6-digit hexadecimal values:

  • #FF5733 represents Red (FF = 255), Green (57 = 87), Blue (33 = 51)

  • This notation compactly represents the full 24-bit color spectrum


Memory Addresses:
Computer memory addresses are almost universally displayed in hexadecimal format, as the base provides a human-readable representation of binary addresses.

MAC Addresses:
Network hardware addresses use hexadecimal notation (e.g., 00:1A:2B:3C:4D:5E).

ASCII Encoding

The American Standard Code for Information Interchange (ASCII) maps numerical values to characters. Each ASCII character is represented by a number from 0 to 127:

  • Decimal 65 = Capital 'A' = Hexadecimal 41 = Binary 01000001

  • Decimal 97 = Lowercase 'a' = Hexadecimal 61 = Binary 01100001

  • Decimal 48 = Digit '0' = Hexadecimal 30 = Binary 00110000


Understanding these conversions is essential for text processing, data encoding, and low-level programming.

Conversion Algorithms

Any Base to Decimal:
Sum each digit multiplied by base raised to its position power.

Decimal to Any Base:
Repeatedly divide by the target base and collect remainders.

Binary to Hex (Direct):
Group binary digits in sets of four and convert each group directly to hex.

Practical Applications

Programming: Debugging, bitwise operations, and data manipulation often require base conversion skills.

Digital Electronics: Logic circuit design uses binary, while documentation often employs hexadecimal for compactness.

Data Representation: Network protocols, file formats, and encryption algorithms frequently use hexadecimal notation.

Conclusion

Mastering number base conversion provides deep insight into how computers represent and manipulate data. From the mathematical elegance of positional notation to the practical applications in computing and digital design, understanding binary, octal, decimal, and hexadecimal systems is an essential skill for any technical practitioner.