Lesson 01: Digital Systems and Number Systems
1.2 Number and Number Systems
Number and Number Systems
A number system is a way to represent numbers.
Ten is an important number for us humans. Most of us have ten fingers and toes, and we certainly prefer to have all ten of each. Because the fingers are convenient for counting, people started using their fingers to count from 1 to 10. It is a decimal system, which is also called a base-10 number system. Even if a lot of number systems are in base 10, humans did not always count in base 10 and we are still using other numeral bases. Here are a few examples:
- The base-60 counting system is still used today with this "60 seconds in a minute; 60 minutes in an hour".
- Base-24 system is used for counting 24 hours to be one day.
- Base-12 system is used for counting one dozen.
Figure 1: Ten fingers on two hands, the possible starting point of the decimal counting
If humans had 6 fingers on their hands, would we be using the Senary system (also known as heximal or Seximal) of numbers?
In a digital system, each digit (bit, wire) has only two possible values: 0 or 1. It is called Binary, or base-2 number system. If there is a long binary number, for example (101110100101)_{binary}, it is not suitable for humans to remember, and it is easily confused. One good way to reduce the length of the binary numbers is by grouping consecutive binary digits into groups of another number system. Therefore, we are using Octal (a base-8 number system) and Hexadecimal (a base-16 number system) to represent a binary number in the digital system.
In mathematics, a 「base」 or a 「radix」 is the number of different digits or combination of digits and letters that a system of counting uses to represent numbers. ~Wiki~
Decimal
Characteristics of the decimal number system are as follows:
- Also called denary
- Base-10
- Uses decimal digits: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
- Positional System — position gives power of the base
- Example:
3845.2 = (3 x 10^{3}) + (8 x 10^{2}) + (4 x 10^{1}) + (5 x 10^{0}) + (2 x 10^{-1}) - Positions: …5 4 3 2 1 0 . -1 -2 -3 …
The base-10 system is a Positional Number System. it means each digit has s different value according to its position. For example: 255 is (2 x 100) + (5 x 10) + (5 x 1). There are a lot of other numeral systems which does not work that way. One of the most famous is Roman numerals, which is not really a positional system. In the Roman number system, The X stands for 10, the V stands for 5, and the I is a one. Twenty-seven in Roman numerals is XXVII ; it is 10 + 10 + 5 + 1 + 1 = 27 in decimal.
Binary
In a computer, all the information is stored using digital signals that translate to binary numbers. A single bit can represent two possible states: on (1) or off (0).
Characteristics of the binary number system are as follows:
- Base-2
- Digits: {0, 1}
- Binary Digits are called bits
- Positional system
- Example:
1101.1_{2} = (1 x 2^{3}) + (1 x 2^{2}) + (0 x 2^{1}) + (1 x 2^{0}) + (1 x 2^{-1})
Octal
Characteristics of the binary number system are as follows:
- Base-8
- Digits: {0, 1, 2, 3, 4, 5, 6, 7}
- A group of 3 binary digits can be used to represent each octal digit
- Positional system
- Example:
357_{8} = (3 x 8^{2}) + (5 x 8^{1}) + (7 x 8^{0})
Hexadecimal
Characteristics of the hexadecimal number system are as follows:
- Base-16
- Digits: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}
- Groups of 4 bits represent each base 16 digit
- Positional system
- Example:
1F4_{16} = (1 x 16^{2}) + (F x 16^{1}) + (4 x 16^{0})
BCD
BCD (Binary Coded Decimal) is a decimal number system, where each decimal digit is represented by a 4-bit binary number.
Do not get confused, BCD is not the same as hexadecimal. The hexadecimal also uses a 4-bit binary to represent one hex digit. Each hex digit is valid up to (F)_{16} representing binary (1111)_{2}. But the one decimal digit is only up to 9 binary (1001)_{2}. This means, that the 4-bit binary can represent 16 numbers (2^{4}), in the BCD number system, the six binary code from (1010)_{2} (decimal 10) to (1111)_{2} (decimal 15) are not used.
The main advantage of BCD is that it allows easy conversion between decimal and binary forms. However, the disadvantage is that the BCD code is wasteful as the states between (1010)_{2} and (1111)_{2} are not used.
Decimal | Binary | Octal | Hexadecimal | BCD |
0 | 0 | 0 | 0 | 0000 |
1 | 1 | 1 | 1 | 0001 |
2 | 10 | 2 | 2 | 0010 |
3 | 11 | 3 | 3 | 0011 |
4 | 100 | 4 | 4 | 0100 |
5 | 101 | 5 | 5 | 0101 |
6 | 110 | 6 | 6 | 0110 |
7 | 111 | 7 | 7 | 0111 |
8 | 1000 | 10 | 8 | 1000 |
9 | 1001 | 11 | 9 | 1001 |
10 | 1010 | 12 | A | 0001 0000 |
11 | 1011 | 13 | B | 0001 0001 |
12 | 1100 | 14 | C | 0001 0010 |
13 | 1101 | 15 | D | 0001 0011 |
14 | 1110 | 16 | E | 0001 0100 |
15 | 1111 | 17 | F | 0001 0101 |
16 | 10000 | 20 | 10 | 0001 0110 |
Conversions between Different Number Systems
Humans want to see and enter numbers in decimal, but computers must store and compute with bits. Therefore, we need to know how to convert a number into different number systems.
- Base-r Numbers to Decimal
- Decimals to Base-r Number
- Binary ↔ Octal
- Binary ↔ Hex
- Octal ↔ Hex
- Binary ↔ Decimal
- Base-r Numbers to Decimal
- Decimals to Base-r Number
- Binary ↔ Octal
- Binary ↔ Hex
- Octal ↔ Hex
- Binary ↔ Decimal
Base-r Numbers to Decimal
To convert any base-r number to decimal:
- Expand base-r number using the positional scheme
- Perform computation using decimal arithmetic
Base-r system to decimal system:
- Determine the positional value of each digit (this depends on the position of the digit and the base of the number system)
- Multiply the obtained positional values (in step 1) by the digits in the corresponding positions.
- Sum the products calculated in Step 2. The total is the equivalent value in decimal.
Ex1: Binary to Decimal
Convert (1101.01)_{2} to decimal.
2^{3} | 2^{2} | 2^{1} | 2^{0} | 2^{-1} | 2^{-2} | |||
Position | 3 | 2 | 1 | 0 | -1 | -2 | ||
(1101.01)_{2} | = | 1 | 1 | 0 | 1 | . | 0 | 1 |
(1101.01)_{2} = (1 x 2^{3}) + (1 x 2^{2}) + (0 x 2^{1}) + (1 x 2^{0}) + (0 x 2^{-1}) + (1 x 2^{-2}) = (13.25)_{10}
Ex2: Octal to Decimal
Convert (432.2)_{8} to decimal.
8^{2} | 8^{1} | 8^{0} | 8^{-1} | |||
Position | 2 | 1 | 0 | -1 | ||
(432.2)_{8} | = | 4 | 3 | 2 | . | 2 |
(432.2)_{8} = (4 x 8^{2}) + (3 x 8^{1}) + (2 x 8^{0}) + (2 x 8^{-1}) = (282.25)_{10}
Ex3: Hexadecimal to Decimal
Convert (B65F)_{16} to decimal.
16^{3} | 16^{2} | 16^{1} | 16^{0} | ||
Position | 3 | 2 | 1 | 0 | |
(B65F)_{16} | = | B | 6 | 5 | F |
(B65F)_{16} = (11 x 16^{3}) + (6 x 16^{2}) + (5 x 16^{1}) + (15 x 16^{0}) = (46,687)_{10}
Decimals to Base-r Number
Use Radix Divide Method
The equation for decimal to base-r number:
Integral Part
- Divide (integral part) by the base- r number:
- Take the remainder as a coefficient
- Take the quotient and repeat the division, until the quotient is equal to zero
Fractional Part
- Multiply the number by the base- r number
- Take the integer (either 0 or 1) as a coefficient
- Take the resultant fraction and repeat the multiplication
Binary ↔ Octal
- 8 = 2^{3}
- Each group of 3 digits in binary represents an Octal digit
Binary to Octal Conversion
- Divide the binary digits into groups of 3 (starting from position 0)
- Convert each group of 3 binary digits to one octal digit.
Example: (10110.01)_{2} to Octal
Octal to Binary Conversion
- Convert each octal digit to a 3-digit binary number (the octal digits may be treated as decimal for this conversion).
- Combine all the resulting binary groups (of 3 digits each) into a single binary number.
Example: (25)_{8} to Binary
Octal | Binary |
0 | 000 |
1 | 001 |
2 | 010 |
3 | 011 |
4 | 100 |
5 | 101 |
6 | 110 |
7 | 111 |
Binary ↔ Hex
- 16 = 2^{4}
- Each group of 4 binary bits represents a Hexadecimal digit
Binary to Hexadecimal
- Divide the binary digits into groups of 4 (starting from the position 0)
- Convert each group of 4 binary digits to one hexadecimal symbol.
Example: (11010.01)_{2} to Hex
Hexadecimal to Binary
- Convert each hexadecimal digit to a 4 digit binary number (the hexadecimal digits may be treated as decimal for this conversion)
- Combine all the resulting binary group (of 4 digits each) into a single binary number
Example: (15)_{16} to Binary
Hex | Binary | Decimal |
0 | 0000 | 0 |
1 | 0001 | 1 |
2 | 0010 | 2 |
3 | 0011 | 3 |
4 | 0100 | 4 |
5 | 0101 | 5 |
6 | 0110 | 6 |
7 | 0111 | 7 |
8 | 1000 | 8 |
9 | 1001 | 9 |
A | 1010 | 10 |
B | 1011 | 11 |
C | 1100 | 12 |
D | 1101 | 13 |
E | 1110 | 14 |
F | 1111 | 15 |
Basically, the number systems can be cataloged into two groups: decimal and binary systems.
Figure 1: Number of Systems
We can easily convert numbers between decimal and binary systems. If you need to convert a BCD number to another system, such as octal, the best solution is to convert the BCD number it to decimal first, then convert to binary, and finally to octal number.
Common Powers
Most of the common powers of base-10 and base-2 number systems are shown as follows:
Power | Preface | Symbol | Value |
10^{-12} | pico | p | 0.000000000001 |
10^{-9} | nano | n | 0.000000001 |
10^{-6} | micro | µ | 0.000001 |
10^{-3} | milli | m | 0.001 |
10^{3} | kilo | K | 1,000 |
10^{6} | mega | M | 1,000,000 |
10^{9} | giga | G | 1,000,000,000 |
10^{12} | tera | T | 1,000,000,000,000 |
Power | Preface | Symbol | Value |
2^{10} | kilo | K | 1,024 |
2^{20} | mega | M | 1,048,576 |
2^{30} | giga | G | 1,073,741,824 |
2^{40} | tera | T | 1,099,511,627,776 |
2^{50} | peta | P | |
2^{60} | exa | E | |
2^{70} | zetta | Z | |
2^{80} | yotta | Y |