Number Systems
Number systems form the foundation of all numerical representations in computing, mathematics, and everyday life. They define how numbers are written, interpreted, and manipulated across different contexts. Each number system operates on a specific base and follows a unique set of rules for representing values.
The most common number systems include:
- Decimal (Base-10): The standard number system used in daily life, built on ten digits (0-9).
- Binary (Base-2): Used in computing, consisting of only two digits (0 and 1).
- Hexadecimal (Base-16): Frequently used in programming and digital systems, utilizing digits 0-9 and letters A-F.
Understanding number systems is essential in fields like computer science, electronics, and data representation. Mastering conversions between these systems allows efficient interpretation of digital data and enhances problem-solving skills in technology and engineering.
Decimal Number System
The Hindu-Arabic or decimal number system is a positional base-10 system. This means:
- Digits: The system has ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
- Place Value: The position of a digit determines its value, based on powers of 10. For example: 10⁶ 10⁵ 10⁴ 10³ 10² 10¹ 10⁰
- Numbers Greater Than 9: Once you reach 9, the next number (10) requires two digits: 1 in the “tens” place and 0 in the “ones” place.
For example, in base-10:
(3x10³) + (0x10²) + (4x10¹) + (5x10⁰) = 3045
Since any digit multiplied by 0 equals 0, we can omit that value from the calculation resulting in:
(3x10³) + (4x10¹) + (5x10⁰) = 3045
Binary Number System
The binary number system is a positional base-2 system. This means:
- Digits: The system has 2 digits: 0, 1.
- Place Value: The position of a digit determines its value, based on powers of 2. For example: 2⁷ 2⁶ 2⁵ 2⁴ 2³ 2² 2¹ 2⁰.
- Numbers Greater Than 1: Once you reach 1, the next number (2) requires two digits: 1 in the “twos” place and 0 in the “ones” place.
For example, in base-2: 1011 1110 0101₂
(1x2¹¹) + (0x2¹⁰) + (1x2⁹) + (1x2⁸) + (1x2⁷) + (1x2⁶) + (1x2⁵) + (0x2⁴) + (0x2³) + (1x2²) + (0x2¹) + (1x2⁰) = 3045
Since any digit multiplied by 0 equals 0, we can omit that value from the calculation resulting in:
(1x2¹¹) + (1x2⁹) + (1x2⁸) + (1x2⁷) + (1x2⁶) + (1x2⁵) + (1x2²) + (1x2⁰) = 3045
Binary Numbers are written in several ways
- A prefix of 0b indicates that the following digits are binary, a convention used in Python and many other programming languages.
- For example: 0b101111100101
- A subscript of “₂” following the digits indicates a binary number.
- For example: 101111100101₂
- Binary numbers are often split into groups of 4 bits (right to left) to make them easier to read.
- For example: 1011 1111 0101₂
- It is common to add zeros on the left side of a binary number to form a complete nibble, byte or word.
- For example: 111110 → 00111110
Hexadecimal Number System
The hecadecimal number system is a positional base-16 system. This means:
- Digits: The system has 16 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
- Place Value: The position of a digit determines its value, based on powers of 16.
- Numbers Greater Than 15: Once you reach 15, the next number (16) requires two digits: 1 in the “sixteens” place and 0 in the “ones” place.
For example, in base-16:
(3x16²) + (0x16¹) + (10x16⁰) = 30A₁₆
Since any digit multiplied by 0 equals 0, we can omit that value from the calculation resulting in:
(3x16²) + (10x16⁰) = 30A₁₆
In general, in any base-(b) number system:
- The available digits range from 0 to (b - 1).
- A number is written using positional notation, where each digit represents a power of the base.
Hexadecimal Numbers are written in several ways
- A prefix of 0x indicates that the following digits are hexadecimal, a convention used in Python and many other programming languages.
- For example: 0x3FE
- A subscript of “₁₆” following the digits indicates a hexadecimal number.
- For example: 3FE₁₆
Conversion Between Number Systems
Useful Tables
Powers of 2
| Power | Value | Power | Value | |
|---|---|---|---|---|
| 2⁰ | 1 | 2⁸ | 256 | |
| 2¹ | 2 | 2⁹ | 512 | |
| 2² | 4 | 2¹⁰ | 1024 | |
| 2³ | 8 | 2¹¹ | 2048 | |
| 2⁴ | 16 | 2¹² | 4096 | |
| 2⁵ | 32 | 2¹³ | 8192 | |
| 2⁶ | 64 | 2¹⁴ | 16,384 | |
| 2⁷ | 128 | 2¹⁵ | 32,768 |
Powers of 16
| Power | Value |
|---|---|
| 16⁰ | 1 |
| 16¹ | 16 |
| 16² | 256 |
| 16³ | 4096 |
Binary to Hexadecimal
| Binary | Hexadecimal | Binary | Hexadecimal | |
|---|---|---|---|---|
| 0000 | 0 | 1000 | 8 | |
| 0001 | 1 | 1001 | 9 | |
| 0010 | 2 | 1010 | A | |
| 0011 | 3 | 1011 | B | |
| 0100 | 4 | 1100 | C | |
| 0101 | 5 | 1101 | D | |
| 0110 | 6 | 1110 | E | |
| 0111 | 7 | 1111 | F |
Decimal to Hexadecimal
Example 1: Convert Decimal 27 to Hexadecimal
Step 1: Find the largest power of 16, smaller than or equal to 27.
- 16² = 256 (too big)
- 16¹ = 16 (this works)
Step 2: Divide 27 by 16¹ (which is 16).
- 27 ÷ 16 = 1 remainder 11
Step 3: Take the remainder (11) and divide by 16⁰ (which is 1).
- 11 ÷ 1 = 11 remainder 0
Step 4: Convert 11 to its hexadecimal digit.
- 11 in decimal = B
Putting it all together, the hexadecimal digits are 1 (from the second step) and B (from the third and fourth steps).
Answer: 1B₁₆
Example 2: Convert Decimal 258 to Hexadecimal
Step 1: Find the largest power of 16, smaller than or equal to 258.
- 16² = 256 (≤ 258, so that’s good)
Step 2: Divide 258 by 16² (which is 256).
- 258 ÷ 256 = 1 remainder 2
Step 3: Take the remainder (2) and divide by 16¹ (which is 16).
- 2 ÷ 16 = 0 remainder 2 (since 2 is smaller than 16)
Step 4: Take the remainder (2) and divide by 16⁰ (which is 1).
- 2 ÷ 1 = 2 remainder 0
Putting it all together, the hexadecimal digits are 1 (from the second step), 0 (from the third step), and 2 (from the fourth step).
Answer: 102₁₆
Hexadecimal to Decimal
Example 1: Convert 1B₁₆ to Decimal
- Identify the hex digits:
- 1 (which is 1 in decimal)
- B (which is 11 in decimal)
- Multiply each digit by 16 to the power of its position:
- 1 x 16¹ = 1 x 16 = 16
- B (11 in decimal) × 16⁰ = 11 x 1 = 11
- Add the results:
- 16 + 11 = 27
Answer: 27
Example 2: Convert A4₁₆ to Decimal
- Identify the hex digits:
- A (which is 10 in decimal)
- 4 (which is 4 in decimal)
- Multiply each digit by 16 to the power of its position:
- A × 16¹ = 10 × 16 = 160
- 4 × 16⁰ = 4 × 1 = 4
- Add the results:
- 160 + 4 = 164
Answer: 164
Decimal to Binary
Example 1: Convert Decimal 4067 to Binary
We keep dividing by powers of 2, starting from the largest that’s less than or equal to 4067:
4067 ÷ 2048 = 1, remainder 2019
2019 ÷ 1024 = 1, remainder 995
995 ÷ 512 = 1, remainder 483
483 ÷ 256 = 1, remainder 227
227 ÷ 128 = 1, remainder 99
99 ÷ 64 = 1, remainder 35
35 ÷ 32 = 1, remainder 3
3 ÷ 16 = 0, remainder 3
3 ÷ 8 = 0, remainder 3
3 ÷ 4 = 0, remainder 3
3 ÷ 2 = 1, remainder 1
1 ÷ 1 = 1, remainder 0
Collecting the quotients (the “1” or “0” in each step) in order, we get the binary digits: 111111100011.
Answer: 1111 1110 0011₂
Example 2: Convert Decimal 45 to Binary
We keep dividing by powers of 2, starting from the largest that’s less than or equal to 45:
45 ÷ 32 = 1, remainder 13
13 ÷ 16 = 0, remainder 13
13 ÷ 8 = 1, remainder 5
5 ÷ 4 = 1, remainder 1
1 ÷ 2 = 0, remainder 1
1 ÷ 1 = 1, remainder 0
Collecting the quotients (the “1” or “0” in each step) in order, we get the binary digits: 101101
Answer: 0010 1101₂ (leading zeros can be added for clarity).
Binary to Decimal
General Steps
- Multiply each binary digit (bit) by 2 raised to its position index (starting from 0 on the right).
- Add all these products together to get the decimal number.
Example 1: Convert 0010 1101₂ to Decimal
Calculation:
(0 × 2⁷) + (0 × 2⁶) + (1 × 2⁵) + (0 × 2⁴) + (1 × 2³) + (1 × 2²) + (0 × 2¹) + (1 × 2⁰)
= (0 × 128) + (0 × 64) + (1 × 32) + (0 × 16) + (1 × 8) + (1 × 4) + (0 × 2) + (1 × 1)
= 0 + 0 + 32 + 0 + 8 + 4 + 0 + 1
= 45
Answer: 45
Example 2: Convert 1111₂ to Decimal
- Bits: 1 1 1 1 (from left to right, that’s positions 3, 2, 1, 0)
Calculation:
(1 × 2³) + (1 × 2²) + (1 × 2¹) + (1 × 2⁰)
= (1 × 8) + (1 × 4) + (1 × 2) + (1 × 1)
= 8 + 4 + 2 + 1
= 15
Answer: 15
Hexadecimal to Binary
Example 1: Convert 1B₁₆ to Binary
- Split into individual hex digits:
- 1
- B
- Convert each digit to its 4-bit binary form:
- 1 in hex → 0001 in binary
- B in hex → 1011 in binary (B = 11 in decimal, which is 1011 in binary)
- Combine the two 4-bit groups:
- 0001 1011
Answer: 0001 1011₂
Example 2: Convert A4¹⁶ to Binary
- Split into individual hex digits:
- A
- 4
- Convert each digit to its 4-bit binary form:
- A in hex → 1010 in binary (A = 10 in decimal, which is 1010 in binary)
- 4 in hex → 0100 in binary
- Combine the two 4-bit groups:
- 1010 0100
Answer: 1010 0100₂
Binary to Hexadecimal
Example 1: Convert 11001110₂ to Hexadecimal
- Split into groups of 4 bits (right to left):
- 11001110 → 1100 1110
- Convert each group to hex:
- 1100 = C
- 1110 = E
Answer: CE₁₆
Example 2: Convert 1111011000₂ to Hexadecimal
- Split into groups of 4 bits (right to left). Add leading zeros if needed:
- 1111011000 → 0011 1101 1000
- Convert each nibble:
- 0011 = 3
- 1101 = D
- 1000 = 8
Answer: 3D8₁₆