Numbers are everywhere-in counting money, measuring distances, or telling time. The system we use daily to represent numbers is called the decimal system, which is based on ten digits (0 to 9). But why do computers use different number systems like binary, octal, and hexadecimal instead of decimal?
Computers operate using electrical signals that are either ON or OFF, which naturally fits a system with only two digits: 0 and 1. This is the binary number system. To make working with binary easier, related systems like octal (base 8) and hexadecimal (base 16) are also used.
In this chapter, we will explore these number systems, understand how they work, and learn how to convert numbers between them. This knowledge is fundamental for understanding how computers process and store data.
A positional number system is a way of representing numbers where the position of each digit affects its value. The value of a digit depends on two things:
The base or radix of a number system tells us how many unique digits are available and how place values increase.
For example, in the decimal system (base 10), digits range from 0 to 9. Each position represents a power of 10:
Here, the number 3572 means:
Adding these gives the total value: 3000 + 500 + 70 + 2 = 3572.
This principle applies to all positional number systems, but the base changes the place values and the allowed digits.
The binary number system uses base 2, meaning it has only two digits: 0 and 1. Each position represents a power of 2, starting from 2⁰ at the rightmost digit.
For example, the binary number 1011 represents:
Adding these gives 8 + 0 + 2 + 1 = 11 in decimal.
| Binary Digit | Position (Right to Left) | Power of 2 | Decimal Value |
|---|---|---|---|
| 1 | 3 | 2³ | 8 |
| 0 | 2 | 2² | 0 |
| 1 | 1 | 2¹ | 2 |
| 1 | 0 | 2⁰ | 1 |
To convert a binary number to decimal, multiply each binary digit by 2 raised to its position index (starting from 0 at the right) and sum all results.
To convert a decimal number to binary, repeatedly divide the number by 2 and record the remainders. The binary number is the remainders read from bottom to top.
The octal number system uses base 8, with digits from 0 to 7. Each digit represents a power of 8.
For example, the octal number 345 means:
Total decimal value = 192 + 32 + 5 = 229.
Octal is closely related to binary because each octal digit corresponds exactly to three binary digits (bits). This makes conversion between octal and binary straightforward.
| Octal Digit | Binary Equivalent (3 bits) |
|---|---|
| 0 | 000 |
| 1 | 001 |
| 2 | 010 |
| 3 | 011 |
| 4 | 100 |
| 5 | 101 |
| 6 | 110 |
| 7 | 111 |
Replace each octal digit with its 3-bit binary equivalent.
Group binary digits into sets of three (starting from the right) and convert each group to its octal digit.
The hexadecimal number system uses base 16. It has 16 digits: 0-9 and letters A-F, where A=10, B=11, C=12, D=13, E=14, and F=15.
Each position represents a power of 16.
For example, the hexadecimal number 2F means:
Total decimal value = 32 + 15 = 47.
Hexadecimal is related to binary because each hex digit corresponds to exactly four binary digits (bits).
| Hex Digit | Decimal Value | Binary Equivalent (4 bits) |
|---|---|---|
| 0 | 0 | 0000 |
| 1 | 1 | 0001 |
| 2 | 2 | 0010 |
| 3 | 3 | 0011 |
| 4 | 4 | 0100 |
| 5 | 5 | 0101 |
| 6 | 6 | 0110 |
| 7 | 7 | 0111 |
| 8 | 8 | 1000 |
| 9 | 9 | 1001 |
| A | 10 | 1010 |
| B | 11 | 1011 |
| C | 12 | 1100 |
| D | 13 | 1101 |
| E | 14 | 1110 |
| F | 15 | 1111 |
Replace each hex digit with its 4-bit binary equivalent.
Group binary digits into sets of four (starting from the right) and convert each group to its hex digit.
Step 1: Divide 156 by 2 and record the remainder.
156 / 2 = 78, remainder = 0
Step 2: Divide 78 by 2.
78 / 2 = 39, remainder = 0
Step 3: Divide 39 by 2.
39 / 2 = 19, remainder = 1
Step 4: Divide 19 by 2.
19 / 2 = 9, remainder = 1
Step 5: Divide 9 by 2.
9 / 2 = 4, remainder = 1
Step 6: Divide 4 by 2.
4 / 2 = 2, remainder = 0
Step 7: Divide 2 by 2.
2 / 2 = 1, remainder = 0
Step 8: Divide 1 by 2.
1 / 2 = 0, remainder = 1
Step 9: Write the remainders from bottom to top:
1 0 0 1 1 1 0 0
Answer: 156 in decimal = 10011100 in binary.
110101 to decimal. Step 1: Write the place values (powers of 2) from right to left:
Positions: 5 4 3 2 1 0
Powers: 2⁵ 2⁴ 2³ 2² 2¹ 2⁰
Values: 32 16 8 4 2 1
Step 2: Multiply each binary digit by its power of 2:
Step 3: Add all the results:
32 + 16 + 0 + 4 + 0 + 1 = 53
Answer: Binary 110101 = Decimal 53.
101110 to its octal equivalent. Step 1: Group the binary digits into sets of 3 from right to left:
101 110
Step 2: Convert each group to decimal (octal digit):
Step 3: Write the octal digits in the same order:
Octal = 65
Answer: Binary 101110 = Octal 65.
2F to binary and decimal. Step 1: Convert each hex digit to 4-bit binary:
Binary equivalent = 00101111
Step 2: Convert hex to decimal:
Decimal = 32 + 15 = 47
Answer: Hexadecimal 2F = Binary 00101111 = Decimal 47.
745 to decimal. Step 1: Write the place values (powers of 8):
Positions: 2 1 0
Values: 8² = 64, 8¹ = 8, 8⁰ = 1
Step 2: Multiply each digit by its place value:
Step 3: Add the results:
448 + 32 + 5 = 485
Answer: Octal 745 = Decimal 485.
When to use: Simplifies conversion between binary and octal/hexadecimal.
When to use: Quick conversion of hex digits to decimal or binary without confusion.
When to use: Manual conversion of decimal numbers to other bases.
When to use: Understanding positional value in all number systems.
When to use: Quick conversions between binary and hex or octal.
Progress tracking is paywalled — subscribe to mark subtopics as understood and save your streak.
Go to practice →