Number System: Binary, Decimal, Octal, Hexadecimal

by Zvonimir Tomesic, CEO

Series: From Binary to Processors: A Deep Dive into Digital Logic

  • Binary 101: The Language Of Computers

  • Number Systems: Binary, Decimal, Octal, Hexadecimal

  • Boolean Algebra: The Foundation Of Digital Logic (coming soon)

  • Logic Gates: The Building Blocks Of Digital Logic (coming soon)

  • Error Correction In Digital Systems: Understanding Hamming Code And Beyond (coming soon)

  • Digital Arithmetic Circuits: From Basic Adders To Complex Chips (coming soon)

  • The Anatomy Of Processors: ALU, Clock, And Core Components (coming soon)

Overview

Understanding various number systems like binary, decimal, octal, and hexadecimal is crucial in computing. These systems each have unique advantages for data processing, representation, and utility in computer environments.

Grasping the Hexadecimal System

The Problem with Binary

Binary, though fundamental to computer operations, is verbose and lacks readability, making it challenging to manage and error-prone for humans.

Why Hexadecimal?

Hexadecimal (base-16) provides a more user-friendly way to represent binary data. Its advantages include:

  • Familiarity: Hexadecimal digits partially resemble our conventional decimal (base-10) system.
  • Density: Hexadecimal is denser than binary. For instance, the number 255 can be represented as FF in hexadecimal but requires 8 bits (11111111) in binary.

Hexadecimal is particularly useful in contexts where binary digits need to be concise yet readable. For instance, in memory addressing, color coding in web design (e.g., #FF5733), and debugging computer programs, hexadecimal provides a compact, comprehensible representation.

Example: e7 in hexadecimal translates to 1110 0111 in binary, equivalent to 231 in decimal.

Binary-Hexadecimal Compatibility

This compatibility simplifies conversions and is one key reason hexadecimal is preferred in certain applications over decimal. Each hexadecimal digit directly translates to a four-bit binary sequence.

Hexadecimal to Binary and Decimal Conversion Table

HexadecimalBinaryDecimal value
000000
100011
200102
300113
401004
501015
601106
701117
810008
910019
A101010
B101111
C110012
D110113
E111014
F111115

Converting Hexadecimal to Decimal

To convert hexadecimal to decimal, multiply each digit by 16 raised to the digit's position and sum them up.

Example:

Converting e7 in hexadecimal to decimal:

e7
=>
14 * 16 ^ 1 + 7 * 16 ^ 0
= 224 + 7
= 231

Exploring the Octal System

The Octal Basics

The octal system (base-8) groups binary numbers into sets of three bits, offering another compact representation.

Octal is especially relevant in the world of computing for its simplicity in converting to and from binary. Historically, it was used in older computer systems and remains useful in modern programming for permissions in Unix and Linux file systems (e.g., chmod 777 for full permissions), and in representing digital displays in some electronic devices.

Example:

Compare the first 15 numbers in decimal, binary, and octal:

DecimalBinaryOctal
000000
100011
200102
300113
401004
501015
601106
701117
8100010
9100111
10101012
11101113
12110014
13110115
14111016
15111117

Octal to Binary Conversion

To convert the decimal number 15 to octal, we group its binary form (1111) into 001 and 111, resulting in 17 in base 8.

First Group

DivideQuotationReminder
2/210
-----------------------------
1/201

If we read Reminder from bottom up, we can see 10 as a binary representation of number 2, because we are talking about octal we know that octal numbers are created from groups of three bits, we will add zero to the end. So we end up with 010.

Second group

DivideQuotationReminder
4/220
-----------------------------
2/210
-----------------------------
1/201

If we read Reminder from bottom up, we can see 100 as a binary representation of number 4.

Then we just concatenate two binary numbers starting from the first group to get the result 010100.

Binary Conversions

Binary to Decimal

For converting binary to decimal, remember that each bit represents a power of two, with the least significant bit (LSB) being (2^0).

Example: To convert 010100 from binary to decimal:

010100
= 0 * 2^5 + 1 * 2^4 + 0 * 2^3 + 1 * 2^2 + 0 * 2^1 + 0 * 2^0
= 0 + 16 + 0 + 4 + 0 + 0
= 20
BinaryValueDecimal
010
020
144
080
11616
0320
Total20

Binary to Octal

Convert binary to octal by dividing the binary number into groups of three, starting from the right.

Example: To convert 010100 (20 in decimal) to octal:

010100 => 010 | 100
= 2 (octal) | 4 (octal)
= 24 (base 8)

First group

binaryvaluedecimal
010
122
040
total2

Second group

binaryvaluedecimal
010
020
144
total4

Then we just concat total starting from first group 24

Binary to Hexadecimal

For binary to hexadecimal, divide the binary number into groups of four.

Example: 010100 (20 in decimal) converts to 14 in hexadecimal.

First group

binaryvaluedecimal
111
020
040
040
total1

Second group

binaryvaluedecimal
010
020
144
080
total4

Then we just concat total starting from first group 14

Octal Conversions

Octal to Binary

To convert from octal to binary, convert each octal digit into a three-bit binary number.

Example: Octal 24 converts to binary 010100.

First Group

DivideQuotationReminder
2/210
-----------------------------
1/201

If we read Reminder from bottom up, we can see 10 as a binary representation of number 2, because we are talking about octal we know that octal numbers are created from groups of three bits, we will add zero to the end. So we end up with 010.

Second group

DivideQuotationReminder
4/220
-----------------------------
2/210
-----------------------------
1/201

If we read Reminder from bottom up, we can see 100 as a binary representation of number 4.

Then we just concatenate two binary numbers starting from the first group to get the result 010100.

Octal to Decimal

To convert from octal to decimal, multiply each digit by 8 raised to the power of its position and sum the results.

Example:

24 (octal)
= 4 * 8^0 + 2 * 8^1
= 4 + 16
= 20 (decimal)

Octal to Hexadecimal

For converting from octal to hexadecimal, first convert to binary, then group into fours and convert to hexadecimal.

Example: Octal 24 becomes 14 in hexadecimal.


20 (Base 10) => 24(base 8) => 14 (Base 16)

The first step is to convert the number to binary (check section Octal to Binary) and then convert binary to hexadecimal

After converting number to binary, we can proceed to hexadecimal conversion.


  010100 => 0001 | 0100

  0001
  => 1*2^0 + 0*2^1 + 0*2^2 + 0*2^3
   = 1 + 0 + 0 + 0
   = 1

  0100
  => 0*2^0 + 0*2^1 + 1*2^2 + 0*2^3
   = 0 + 0 + 4 + 0
   = 4

  00010100 (base 2) = 14 (base 16)

Conclusion

Understanding these number systems is fundamental in computing and digital electronics. Each system has unique features suited for specific applications, enhancing the efficiency of data representation and processing. Through mastering these conversions, one gains deeper insights into how data is managed within computer systems.

More articles

Linux Schedulers - Ensuring Optimal System Performance

Evolution and functionality of Linux schedulers, from simple round-robin to the Completely Fair Scheduler and real-time alternatives, emphasizing their critical role in balancing system responsiveness, fairness, and efficiency across various computing environments.

Read more

Binary 101: The Language of Computers

Explore the foundational principles of digital logic, from the simplicity of binary arithmetic to the intricacies of addition, subtraction, multiplication, and division in the binary system

Read more

Tell us about your project

Our offices

  • Zagreb
    Bozidara Magovca 14
    10000, Zagreb, Croatia