Se connecterS'abonner

Chapitre 5

Operations on number systems

Lecture : 49 minQuiz de 16 questions

# Operations on number systems ## Notions on number systems # Notions on Number Systems\n\n## Introduction\nWelcome to the exciting world of number systems! In computer science, understanding how numbers are represented is fundamental. While we use the decimal system every day, computers rely on other systems, particularly the binary system. This lesson will introduce you to different number systems, their characteristics, and why they are crucial in computing.\n\n## Key Concepts\n\n### What is a Number System?\nA number system is a systematic way of representing numbers using a set of symbols or digits. The value of a digit often depends on its position within the number.\n\n* **Base (or Radix):** This is the total number of unique digits or symbols used in a particular number system. For example, the decimal system has a base of 10.\n* **Positional Notation:** In a positional number system, the value of each digit in a number depends on its position. Each position represents a power of the base.\n * General form: \( (d_n d_{n-1} ... d_1 d_0 . d_{-1} d_{-2} ... d_{-m})_b = d_n \times b^n + d_{n-1} \times b^{n-1} + ... + d_1 \times b^1 + d_0 \times b^0 + d_{-1} \times b^{-1} + ... + d_{-m} \times b^{-m} \)\n\n### Common Number Systems\n\n#### 1. Decimal System (Base-10)\n* **Digits:** 0, 1, 2, 3, 4, 5, 6, 7, 8, 9\n* This is the number system we use in our daily lives.\n* **Example:** The number \( 456_{10} \) means \( 4 \times 10^2 + 5 \times 10^1 + 6 \times 10^0 \).\n\n#### 2. Binary System (Base-2)\n* **Digits:** 0, 1 (these are called 'bits')\n* This is the fundamental language of computers. Computers use binary because electric circuits have two states: ON (represented by 1) or OFF (represented by 0).\n* **Example:** The number \( 1101_2 \) means \( 1 \times 2^3 + 1 \times 2^2 + 0 \times 2^1 + 1 \times 2^0 \).\n\n#### 3. Octal System (Base-8)\n* **Digits:** 0, 1, 2, 3, 4, 5, 6, 7\n* It is used as a compact way to represent binary numbers because 3 binary bits can represent one octal digit (since \( 2^3 = 8 \)).\n* **Example:** The number \( 37_8 \) means \( 3 \times 8^1 + 7 \times 8^0 \).\n\n#### 4. Hexadecimal System (Base-16)\n* **Digits:** 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F\n * Here, A = 10, B = 11, C = 12, D = 13, E = 14, F = 15.\n* Used as a shorthand for binary because 4 binary bits can represent one hexadecimal digit (since \( 2^4 = 16 \)). It's commonly used for memory addresses, color codes (e.g., #FFFFFF), and MAC addresses.\n* **Example:** The number \( 1AF_{16} \) means \( 1 \times 16^2 + A \times 16^1 + F \times 16^0 \).\n\n### Importance in Computer Science\n* Computers process information using binary states.\n* Octal and Hexadecimal systems provide a more human-readable and compact representation of long binary numbers, making it easier for programmers and engineers to work with computer memory, data, and system configurations.\n\n## Vocabulary\n* **Number System:** A way of representing numbers.\n* **Base (Radix):** The number of unique digits used in a number system.\n* **Digit:** A symbol used to represent a number.\n* **Binary:** A base-2 number system, using only 0s and 1s.\n* **Octal:** A base-8 number system, using digits 0-7.\n* **Decimal:** A base-10 number system, using digits 0-9.\n* **Hexadecimal:** A base-16 number system, using digits 0-9 and A-F.\n* **Bit:** A single binary digit (0 or 1).\n* **Positional Notation:** A system where the value of a digit depends on its position in the number.\n\n## Examples\n\n### 1. Converting Binary to Decimal\nConvert \( 1011_2 \) to its decimal equivalent:\n\[ 1 \times 2^3 + 0 \times 2^2 + 1 \times 2^1 + 1 \times 2^0 \]\n\[ = 1 \times 8 + 0 \times 4 + 1 \times 2 + 1 \times 1 \]\n\[ = 8 + 0 + 2 + 1 = 11_{10} \]\n\n### 2. Converting Octal to Decimal\nConvert \( 47_8 \) to its decimal equivalent:\n\[ 4 \times 8^1 + 7 \times 8^0 \]\n\[ = 4 \times 8 + 7 \times 1 \]\n\[ = 32 + 7 = 39_{10} \]\n\n### 3. Converting Hexadecimal to Decimal\nConvert \( 2D_{16} \) to its decimal equivalent:\n\[ 2 \times 16^1 + D \times 16^0 \quad \text{ (where D = 13)} \]\n\[ = 2 \times 16 + 13 \times 1 \]\n\[ = 32 + 13 = 45_{10} \]\n\n### 4. Relationship between Binary, Octal, and Hexadecimal\nConsider the binary number \( 110101_2 \).\n\n* **To convert to Octal:** Group the binary digits into sets of three from the right.\n * \( 110 \ 101 \)\n * Convert each group to its octal equivalent:\n * \( 110_2 = 6_8 \)\n * \( 101_2 = 5_8 \)\n * Therefore, \( 110101_2 = 65_8 \).\n\n* **To convert to Hexadecimal:** Group the binary digits into sets of four from the right (add leading zeros if needed).\n * \( 0011 \ 0101 \) (We added two leading zeros to make a full group of four)\n * Convert each group to its hexadecimal equivalent:\n * \( 0011_2 = 3_{16} \)\n * \( 0101_2 = 5_{16} \)\n * Therefore, \( 110101_2 = 35_{16} \).\n\n## Exercises\n\n1. Identify the base for each of the following number systems:\n a) Decimal\n b) Binary\n c) Octal\n d) Hexadecimal\n2. What is the largest digit allowed in the octal number system?\n3. Convert the following binary numbers to decimal:\n a) \( 101_2 \)\n b) \( 1110_2 \)\n c) \( 10001_2 \)\n4. Convert the following octal numbers to decimal:\n a) \( 25_8 \)\n b) \( 102_8 \)\n5. Convert the following hexadecimal numbers to decimal:\n a) \( A5_{16} \)\n b) \( 1F_{16} \)\n\n## Assignment\n\n1. Explain why computers use the binary number system instead of the decimal system.\n2. Convert the binary number \( 11101011_2 \) to its equivalent in:\n a) Decimal\n b) Octal\n c) Hexadecimal\n3. Convert the hexadecimal color code \( FFE040_{16} \) to its decimal representation for each of its red, green, and blue components. (Hint: group into three pairs of two digits each, like FF, E0, 40).\n4. A memory address is given as \( 4B3A_{16} \). What is its decimal equivalent?\n\n## Summary\nIn this lesson, we explored the fundamental concepts of number systems, which are essential for understanding how computers work. We learned about:\n* **Decimal (Base-10):** Our everyday system.\n* **Binary (Base-2):** The language of computers, using 0s and 1s.\n* **Octal (Base-8):** A compact way to represent binary (groups of 3 bits).\n* **Hexadecimal (Base-16):** An even more compact way to represent binary (groups of 4 bits), often used for addresses and color codes.\n\nUnderstanding these systems provides a strong foundation for further studies in computer science and programming. ## Conversion from any base, to base 10 ### Introduction Welcome to this lesson on number system conversions! In Computer Science, you'll encounter different ways to represent numbers. While humans primarily use the decimal (base 10) system, computers fundamentally operate using the binary (base 2) system. Other systems like octal (base 8) and hexadecimal (base 16) are also used as convenient shorthand for binary. To truly understand how computers process information, it's crucial to know how to convert numbers from any of these bases into the familiar base 10 system. This lesson will equip you with the knowledge and skills to perform these conversions accurately. ### Key Concepts #### Understanding Number Systems Every number system has a **base** (also known as a **radix**), which determines the number of unique digits it uses to represent values. * **Base (Radix):** The number of unique digits (including zero) used in a number system. For example, base 10 uses 10 digits (0-9), base 2 uses 2 digits (0-1), base 8 uses 8 digits (0-7), and base 16 uses 16 digits (0-9 and A-F, where A=10, B=11, C=12, D=13, E=14, F=15). * **Place Value:** In any number system, the position of a digit determines its value. Each position represents a power of the base. #### The Conversion Principle: From Any Base to Base 10 To convert a number from any base \(b\) to base 10, you multiply each digit by its corresponding **place value** (which is the base raised to the power of its position) and then sum up all these products. The powers are assigned starting from 0 for the digit immediately to the left of the radix point (decimal point for base 10), increasing by one for each position to the left, and decreasing by one (negative powers) for each position to the right. The general formula for converting a number \( (d_n d_{n-1} ... d_1 d_0 . d_{-1} d_{-2} ... d_{-m})_b \) to base 10 is: \[ (d_n d_{n-1} ... d_1 d_0 . d_{-1} d_{-2} ... d_{-m})_b = d_n \times b^n + d_{n-1} \times b^{n-1} + ... + d_1 \times b^1 + d_0 \times b^0 + d_{-1} \times b^{-1} + d_{-2} \times b^{-2} + ... + d_{-m} \times b^{-m} \] Where: * \(d\) represents a digit in the number. * \(b\) is the base of the number system. * The superscripts (\(n, n-1, ..., 0, -1, -2, ... -m\)) represent the **positional power** of the base for each digit. #### Steps for Conversion 1. **Identify the Base:** Determine the base \(b\) of the given number. 2. **Identify Digits and Positions:** Write down the number and identify each digit's position. Assign powers to the base starting from 0 for the digit immediately to the left of the radix point. Increase powers by 1 for digits moving left, and decrease by 1 (negative powers) for digits moving right. 3. **Multiply and Sum:** For each digit, multiply the digit by the base raised to its corresponding power. 4. **Calculate the Sum:** Add all the products together. The result is the number in base 10. ### Vocabulary * **Number System:** A set of symbols and rules for representing numbers. * **Base (Radix):** The number of unique digits, including zero, used in a number system. * **Decimal System (Base 10):** The number system we use daily, employing digits 0-9. * **Binary System (Base 2):** A number system using only two digits, 0 and 1, fundamental to computers. * **Octal System (Base 8):** A number system using digits 0-7, often used as a compact representation of binary numbers. * **Hexadecimal System (Base 16):** A number system using digits 0-9 and letters A-F (where A=10, B=11, C=12, D=13, E=14, F=15), also used as a compact representation of binary. * **Place Value:** The value of a digit determined by its position within a number. * **Digit:** A single symbol used to form numbers. * **Power (Exponent):** An indication of the number of times a base is multiplied by itself. * **Radix Point:** The symbol (e.g., a dot or period) that separates the integer part from the fractional part of a number in any base (equivalent to a decimal point in base 10). ### Examples #### Example 1: Binary to Decimal **Problem:** Convert \( (1011)_2 \) to base 10. **Solution:** 1. **Digits and Powers:** * \(1 \times 2^3\) * \(0 \times 2^2\) * \(1 \times 2^1\) * \(1 \times 2^0\) 2. **Calculation:** \( (1011)_2 = (1 \times 2^3) + (0 \times 2^2) + (1 \times 2^1) + (1 \times 2^0) \) \( = (1 \times 8) + (0 \times 4) + (1 \times 2) + (1 \times 1) \) \( = 8 + 0 + 2 + 1 \) \( = (11)_{10} \) **Problem:** Convert \( (110.101)_2 \) to base 10. **Solution:** 1. **Digits and Powers:** * \(1 \times 2^2\) * \(1 \times 2^1\) * \(0 \times 2^0\) * \(1 \times 2^{-1}\) * \(0 \times 2^{-2}\) * \(1 \times 2^{-3}\) 2. **Calculation:** \( (110.101)_2 = (1 \times 2^2) + (1 \times 2^1) + (0 \times 2^0) + (1 \times 2^{-1}) + (0 \times 2^{-2}) + (1 \times 2^{-3}) \) \( = (1 \times 4) + (1 \times 2) + (0 \times 1) + (1 \times 0.5) + (0 \times 0.25) + (1 \times 0.125) \) \( = 4 + 2 + 0 + 0.5 + 0 + 0.125 \) \( = (6.625)_{10} \) #### Example 2: Octal to Decimal **Problem:** Convert \( (247)_8 \) to base 10. **Solution:** 1. **Digits and Powers:** * \(2 \times 8^2\) * \(4 \times 8^1\) * \(7 \times 8^0\) 2. **Calculation:** \( (247)_8 = (2 \times 8^2) + (4 \times 8^1) + (7 \times 8^0) \) \( = (2 \times 64) + (4 \times 8) + (7 \times 1) \) \( = 128 + 32 + 7 \) \( = (167)_{10} \) #### Example 3: Hexadecimal to Decimal **Problem:** Convert \( (3A5)_{16} \) to base 10. (Remember: A=10) **Solution:** 1. **Digits and Powers:** * \(3 \times 16^2\) * \(A (10) \times 16^1\) * \(5 \times 16^0\) 2. **Calculation:** \( (3A5)_{16} = (3 \times 16^2) + (10 \times 16^1) + (5 \times 16^0) \) \( = (3 \times 256) + (10 \times 16) + (5 \times 1) \) \( = 768 + 160 + 5 \) \( = (933)_{10} \) **Problem:** Convert \( (F.4)_{16} \) to base 10. (Remember: F=15) **Solution:** 1. **Digits and Powers:** * \(F (15) \times 16^0\) * \(4 \times 16^{-1}\) 2. **Calculation:** \( (F.4)_{16} = (15 \times 16^0) + (4 \times 16^{-1}) \) \( = (15 \times 1) + (4 \times \frac{1}{16}) \) \( = 15 + 0.25 \) \( = (15.25)_{10} \) ### Exercises Convert the following numbers to base 10: 1. \( (1101)_2 \) 2. \( (10110)_2 \) 3. \( (37)_8 \) 4. \( (145)_8 \) 5. \( (2F)_{16} \) 6. \( (B1)_{16} \) 7. \( (101.1)_2 \) 8. \( (1A.2)_{16} \) ### Assignment Continue practicing these conversions at home: 1. Convert \( (111101)_2 \) to base 10. 2. Convert \( (507)_8 \) to base 10. 3. Convert \( (ABC)_{16} \) to base 10. 4. Convert \( (10.11)_2 \) to base 10. 5. Convert \( (7F.8)_{16} \) to base 10. 6. A computer sensor records a temperature value as \( (1001011)_2 \). What is this temperature in the more common base 10 system? ### Summary In this lesson, we explored the essential process of converting numbers from any base to base 10. You learned that any number, regardless of its original base, can be expressed in our familiar decimal system by understanding its **place values**. The core principle involves multiplying each digit by its corresponding positional power of the base and then summing these products. Mastering this skill is fundamental for working with different number systems in Computer Science, enabling you to interpret and manipulate data effectively, regardless of how it's represented. ## Conversion from base 10, to any base ### Introduction Welcome to this lesson on number system conversions! In our daily lives, we use the decimal system, which is base 10. However, computers operate using different number systems, primarily binary (base 2). Understanding how to convert numbers from base 10 to other bases is a fundamental skill in Computer Science. This lesson will teach you a systematic method to perform these conversions accurately. ### Key Concepts #### Understanding Number Systems A number system is a way of representing numbers. Each number system has a 'base' or 'radix' which determines the number of unique digits available in that system. * **Base 10 (Decimal System):** This is the system we use every day. It has ten unique digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9). The position of a digit determines its value, which is a power of 10. * **Other Bases:** Computers use systems like binary (base 2), octal (base 8), and hexadecimal (base 16). Each has a different set of digits and positional values. #### The Division Method for Base Conversion The most common method to convert a number from base 10 to any other base is the **repeated division method**. Here's how it works: 1. **Divide the Decimal Number:** Divide the base 10 number by the target base. 2. **Record the Remainder:** Note down the remainder of this division. This remainder will be one of the digits in the new base. 3. **Use the Quotient:** Take the quotient from the division and use it as the new number to be divided. 4. **Repeat:** Continue steps 1-3 until the quotient becomes 0. 5. **Read the Result:** The digits in the new base are formed by reading the remainders from bottom to top (the last remainder is the Most Significant Digit, and the first remainder is the Least Significant Digit). #### Handling Bases Greater Than 10 When converting to bases greater than 10, such as hexadecimal (base 16), we need more than 10 unique digits. For remainders from 10 to 15, we use letters: * 10 = A * 11 = B * 12 = C * 13 = D * 14 = E * 15 = F ### Vocabulary * **Base 10 (Decimal):** The standard number system with ten digits (0-9). * **Base (Radix):** The number of unique digits, including zero, used to represent numbers in a positional numeral system. * **Binary (Base 2):** A number system with two digits (0 and 1), fundamental to computers. * **Octal (Base 8):** A number system with eight digits (0-7). * **Hexadecimal (Base 16):** A number system with sixteen digits (0-9 and A-F). * **Dividend:** The number being divided. * **Divisor:** The number by which another number is divided (the target base in this case). * **Quotient:** The result obtained by dividing one number by another. * **Remainder:** The amount left over after a division when the dividend is not perfectly divisible by the divisor. ### Examples Let's apply the division method to some examples. #### Example 1: Convert \( 25_{10} \) to Binary (Base 2) | Division | Quotient | Remainder | | :------- | :------- | :-------- | | \( 25 \div 2 \) | 12 | 1 | | \( 12 \div 2 \) | 6 | 0 | | \( 6 \div 2 \) | 3 | 0 | | \( 3 \div 2 \) | 1 | 1 | | \( 1 \div 2 \) | 0 | 1 | Reading the remainders from bottom to top, we get \( 11001_2 \). Therefore, \( 25_{10} = 11001_2 \). #### Example 2: Convert \( 156_{10} \) to Octal (Base 8) | Division | Quotient | Remainder | | :-------- | :------- | :-------- | | \( 156 \div 8 \) | 19 | 4 | | \( 19 \div 8 \) | 2 | 3 | | \( 2 \div 8 \) | 0 | 2 | Reading the remainders from bottom to top, we get \( 234_8 \). Therefore, \( 156_{10} = 234_8 \). #### Example 3: Convert \( 250_{10} \) to Hexadecimal (Base 16) | Division | Quotient | Remainder | | :--------- | :------- | :-------- | | \( 250 \div 16 \) | 15 | 10 (A) | | \( 15 \div 16 \) | 0 | 15 (F) | Reading the remainders from bottom to top, and replacing 10 with A and 15 with F, we get \( FA_{16} \). Therefore, \( 250_{10} = FA_{16} \). ### Exercises Try converting the following decimal numbers to the specified bases. Show your working clearly. 1. Convert \( 47_{10} \) to Binary. 2. Convert \( 99_{10} \) to Octal. 3. Convert \( 175_{10} \) to Hexadecimal. 4. Convert \( 63_{10} \) to Base 3. 5. Convert \( 32_{10} \) to Base 5. ### Assignment Practice these conversions at home. Remember to follow the division method and keep track of your remainders. 1. Convert \( 78_{10} \) to Binary. 2. Convert \( 201_{10} \) to Octal. 3. Convert \( 400_{10} \) to Hexadecimal. 4. Convert \( 120_{10} \) to Base 7. 5. Convert \( 100_{10} \) to Binary and then to Octal. ### Summary In this lesson, we learned the crucial skill of converting numbers from our familiar base 10 system to any other base. The **repeated division method** is the key technique: repeatedly divide the decimal number by the target base, record the remainders, and read them from bottom to top. We also covered how to represent remainders greater than 9 using letters (A-F) for bases like hexadecimal. Mastering these conversions is essential for understanding how computers process and store numerical data. ## Conversion from base 2, to 8 and 16 ### Introduction Welcome to this lesson on number system conversions! In computer science, we often deal with different ways of representing numbers. While humans primarily use the decimal (base 10) system, computers understand binary (base 2). To make it easier for programmers to work with long binary strings, other number systems like octal (base 8) and hexadecimal (base 16) are used as convenient shorthand representations of binary numbers. In this lesson, we will learn how to convert numbers between these bases quickly and efficiently. ### Key Concepts #### Understanding Number Bases Before we dive into conversions, let's briefly recall the number systems we'll be working with: * **Binary (Base 2):** Uses only two digits: 0 and 1. Each position represents a power of 2. Example: \( 1011_2 \) * **Octal (Base 8):** Uses eight digits: 0, 1, 2, 3, 4, 5, 6, 7. Each position represents a power of 8. Example: \( 27_8 \) * **Hexadecimal (Base 16):** Uses sixteen digits: 0-9 and A-F (where A=10, B=11, C=12, D=13, E=14, F=15). Each position represents a power of 16. Example: \( 3F_{16} \) #### Binary to Octal Conversion Converting a binary number to an octal number is straightforward because 8 is a power of 2 (\( 2^3 = 8 \)). This means every three binary digits (bits) correspond to exactly one octal digit. ##### Steps: 1. **Group Bits:** Starting from the rightmost digit, group the binary digits into sets of three. If the leftmost group has fewer than three digits, add leading zeros to complete the group. 2. **Convert Each Group:** Convert each 3-bit group into its equivalent octal digit. ##### 3-Bit Binary to Octal Mapping: * 000 \( \rightarrow \) 0 * 001 \( \rightarrow \) 1 * 010 \( \rightarrow \) 2 * 011 \( \rightarrow \) 3 * 100 \( \rightarrow \) 4 * 101 \( \rightarrow \) 5 * 110 \( \rightarrow \) 6 * 111 \( \rightarrow \) 7 #### Octal to Binary Conversion This is the reverse of binary to octal conversion. Since each octal digit corresponds to exactly three binary digits, you just need to replace each octal digit with its 3-bit binary equivalent. ##### Steps: 1. **Replace Digits:** For each octal digit, write down its 3-bit binary representation. 2. **Combine:** Combine all the 3-bit binary strings to form the final binary number. #### Binary to Hexadecimal Conversion Similar to octal, hexadecimal is also a power of 2 (\( 2^4 = 16 \)). This means every four binary digits (bits) correspond to exactly one hexadecimal digit. ##### Steps: 1. **Group Bits:** Starting from the rightmost digit, group the binary digits into sets of four. If the leftmost group has fewer than four digits, add leading zeros to complete the group. 2. **Convert Each Group:** Convert each 4-bit group into its equivalent hexadecimal digit. ##### 4-Bit Binary to Hexadecimal Mapping: * 0000 \( \rightarrow \) 0 * 0001 \( \rightarrow \) 1 * 0010 \( \rightarrow \) 2 * 0011 \( \rightarrow \) 3 * 0100 \( \rightarrow \) 4 * 0101 \( \rightarrow \) 5 * 0110 \( \rightarrow \) 6 * 0111 \( \rightarrow \) 7 * 1000 \( \rightarrow \) 8 * 1001 \( \rightarrow \) 9 * 1010 \( \rightarrow \) A * 1011 \( \rightarrow \) B * 1100 \( \rightarrow \) C * 1101 \( \rightarrow \) D * 1110 \( \rightarrow \) E * 1111 \( \rightarrow \) F #### Hexadecimal to Binary Conversion This is the reverse of binary to hexadecimal conversion. Since each hexadecimal digit corresponds to exactly four binary digits, you just need to replace each hexadecimal digit with its 4-bit binary equivalent. ##### Steps: 1. **Replace Digits:** For each hexadecimal digit, write down its 4-bit binary representation. 2. **Combine:** Combine all the 4-bit binary strings to form the final binary number. ### Vocabulary * **Binary (Base 2):** A number system that uses only two digits, 0 and 1, fundamental to computing. * **Octal (Base 8):** A number system that uses eight digits, 0 through 7, often used as a shorthand for binary. * **Hexadecimal (Base 16):** A number system that uses sixteen digits (0-9 and A-F), widely used in computing for memory addresses and color codes. * **Bit:** A binary digit, the smallest unit of data in a computer, represented as either 0 or 1. * **Digit:** A single symbol used to form numbers in a number system. * **Base (Radix):** The number of unique digits, including zero, used to represent numbers in a positional number system. ### Examples #### Example 1: Binary to Octal Convert \( 1011101_2 \) to Octal. **Solution:** 1. Group in threes from the right: \( 1 \ 011 \ 101 \) 2. Add leading zeros to the first group: \( 001 \ 011 \ 101 \) 3. Convert each group: * \( 001_2 \ = 1_8 \) * \( 011_2 \ = 3_8 \) * \( 101_2 \ = 5_8 \) 4. Combine: \( 135_8 \) So, \( 1011101_2 = 135_8 \). #### Example 2: Binary to Hexadecimal Convert \( 110101101001_2 \) to Hexadecimal. **Solution:** 1. Group in fours from the right: \( 1101 \ 0110 \ 1001 \) 2. Convert each group: * \( 1101_2 \ = D_{16} \) * \( 0110_2 \ = 6_{16} \) * \( 1001_2 \ = 9_{16} \) 3. Combine: \( D69_{16} \) So, \( 110101101001_2 = D69_{16} \). #### Example 3: Octal to Binary Convert \( 723_8 \) to Binary. **Solution:** 1. Convert each octal digit to 3-bit binary: * \( 7_8 \ = 111_2 \) * \( 2_8 \ = 010_2 \) * \( 3_8 \ = 011_2 \) 2. Combine: \( 111010011_2 \) So, \( 723_8 = 111010011_2 \). #### Example 4: Hexadecimal to Binary Convert \( A5E_{16} \) to Binary. **Solution:** 1. Convert each hexadecimal digit to 4-bit binary: * \( A_{16} \ = 1010_2 \) * \( 5_{16} \ = 0101_2 \) * \( E_{16} \ = 1110_2 \) 2. Combine: \( 101001011110_2 \) So, \( A5E_{16} = 101001011110_2 \). ### Exercises Try to solve these problems to test your understanding: 1. Convert \( 11011011_2 \) to Octal. 2. Convert \( 1010011110_2 \) to Hexadecimal. 3. Convert \( 670_8 \) to Binary. 4. Convert \( F2B_{16} \) to Binary. 5. What is the octal equivalent of \( 11110000_2 \)? 6. What is the hexadecimal equivalent of \( 10110110111_2 \)? ### Assignment Complete the following conversions and show your working: 1. Convert the binary number \( 1011001101_2 \) to its octal equivalent. 2. Convert the binary number \( 11101011000101_2 \) to its hexadecimal equivalent. 3. Convert the octal number \( 451_8 \) to its binary equivalent. 4. Convert the hexadecimal number \( C3D_{16} \) to its binary equivalent. 5. A computer memory address is given as \( 1A7_{16} \). What is this address in binary? 6. If a digital system outputs the binary code \( 010110111_2 \), what would be its representation in octal? ### Summary In this lesson, we explored the quick and efficient methods for converting between binary, octal, and hexadecimal number systems. We learned that: * To convert **Binary to Octal**, group binary digits in threes starting from the right and convert each group to its octal equivalent. * To convert **Octal to Binary**, replace each octal digit with its 3-bit binary equivalent. * To convert **Binary to Hexadecimal**, group binary digits in fours starting from the right and convert each group to its hexadecimal equivalent. * To convert **Hexadecimal to Binary**, replace each hexadecimal digit with its 4-bit binary equivalent. These conversions are vital tools for anyone working with computer systems, as they simplify the representation and understanding of binary data. ## Conversion from base 16, to base 2 and 8, and addition in base 2, 8 and 16 ### Introduction Welcome to this lesson on number systems! In computer science, numbers are often represented in different bases other than the familiar decimal (base 10) system. We've previously explored binary (base 2) and octal (base 8). Today, we'll dive into hexadecimal (base 16) and learn how to convert numbers between these bases. We will also master the crucial skill of adding numbers directly within the binary, octal, and hexadecimal systems. ### Key Concepts #### 1. Conversion from Base 16 (Hexadecimal) to Base 2 (Binary) Hexadecimal is a base-16 number system, which means it uses 16 distinct symbols. These are the digits 0-9 and the letters A-F, where A represents 10, B represents 11, and so on, up to F representing 15. Binary (base 2) uses only two digits: 0 and 1. Converting from hexadecimal to binary is straightforward because each hexadecimal digit can be directly represented by a group of four binary digits (bits). ##### Hexadecimal to 4-bit Binary Equivalents | Hexadecimal | Decimal | Binary | | :---------- | :------ | :----- | | 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 | ##### Steps: 1. Take each hexadecimal digit individually. 2. Convert each hex digit to its 4-bit binary equivalent using the table above. 3. Combine the resulting 4-bit binary groups to form the final binary number. #### 2. Conversion from Base 16 (Hexadecimal) to Base 8 (Octal) To convert a hexadecimal number to an octal number, it is usually easiest to convert the hexadecimal number to binary first, and then convert the binary number to octal. ##### Steps: 1. **Hexadecimal to Binary:** Convert the hexadecimal number to its binary equivalent (as shown in the previous section). 2. **Binary to Octal:** Group the binary digits into groups of three, starting from the rightmost digit. If the leftmost group has fewer than three digits, add leading zeros to complete the group. 3. Convert each 3-bit binary group to its octal equivalent. ##### 3-bit Binary to Octal Equivalents | Binary | Octal | | :----- | :---- | | 000 | 0 | | 001 | 1 | | 010 | 2 | | 011 | 3 | | 100 | 4 | | 101 | 5 | | 110 | 6 | | 111 | 7 | #### 3. Addition in Base 2 (Binary) Binary addition follows similar rules to decimal addition, but with only two digits (0 and 1). When the sum of bits in a column is 2, we write down 0 and carry over 1 to the next column (since \( (1+1)_{10} = (10)_2 \)). ##### Rules for Binary Addition: * \( 0 + 0 = 0 \) * \( 0 + 1 = 1 \) * \( 1 + 0 = 1 \) * \( 1 + 1 = 0 \) and carry \( 1 \) to the next column. * \( 1 + 1 + 1 = 1 \) and carry \( 1 \) to the next column (when adding three bits, e.g., two bits from the numbers and one carry-in). #### 4. Addition in Base 8 (Octal) Octal addition also uses the concept of carrying over. Digits used are 0-7. If the sum of digits in a column is 8 or more, you subtract 8 from the sum, write down the result, and carry over 1 to the next column. ##### Steps: 1. Add the digits in each column, starting from the rightmost column. 2. If the sum is less than 8, write it down. 3. If the sum is 8 or more, divide the sum by 8. The remainder is the digit to write down, and the quotient is the carry-over to the next column. * For example, \( 5 + 4 = 9 \). In octal, \( 9 = 1 \times 8 + 1 \). So, write down \( 1 \) and carry \( 1 \). #### 5. Addition in Base 16 (Hexadecimal) Hexadecimal addition involves digits 0-9 and letters A-F (representing 10-15). If the sum of digits in a column is 16 or more, you subtract 16 from the sum, write down the hexadecimal equivalent of the result, and carry over 1 to the next column. ##### Steps: 1. Convert any letter digits (A-F) to their decimal equivalents (10-15) for addition. 2. Add the digits in each column, starting from the rightmost column. 3. If the sum is less than 16, convert it back to its hexadecimal symbol (if it's 10-15) and write it down. 4. If the sum is 16 or more, divide the sum by 16. The remainder is the digit to write down (converted to hex symbol if needed), and the quotient is the carry-over to the next column. * For example, \( B + 7 = 11 + 7 = 18 \). In hexadecimal, \( 18 = 1 \times 16 + 2 \). So, write down \( 2 \) and carry \( 1 \). ### Vocabulary * **Base (Radix):** The number of unique digits, including zero, used to represent numbers in a positional numeral system. For example, decimal is base 10, binary is base 2. * **Binary (Base 2):** A number system that uses only two digits: 0 and 1. It is the fundamental language of computers. * **Octal (Base 8):** A number system that uses eight digits: 0, 1, 2, 3, 4, 5, 6, and 7. * **Hexadecimal (Base 16):** A number system that uses sixteen digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. It is commonly used in computing as a shorthand for binary. * **Carry:** A digit transferred from one column to another column of higher positional value when the sum of digits in a column exceeds the base. ### Examples #### Example 1: Convert \( (3F5)_{16} \) to Binary 1. Break down the hexadecimal number: * \( 3 \) * \( F \) * \( 5 \) 2. Convert each hex digit to its 4-bit binary equivalent: * \( 3_{16} = 0011_2 \) * \( F_{16} = 1111_2 \) * \( 5_{16} = 0101_2 \) 3. Combine the binary groups: * \( (3F5)_{16} = (0011 \ 1111 \ 0101)_2 = (1111110101)_2 \) (leading zeros are often omitted for the most significant digit). #### Example 2: Convert \( (A7)_{16} \) to Octal 1. **Hexadecimal to Binary:** * \( A_{16} = 1010_2 \) * \( 7_{16} = 0111_2 \) * So, \( (A7)_{16} = (10100111)_2 \) 2. **Binary to Octal:** Group the binary digits into threes from right to left. * \( 10 \ 100 \ 111 \) (add a leading zero to the first group if needed: \( 010 \ 100 \ 111 \)) 3. Convert each 3-bit group to its octal equivalent: * \( 010_2 = 2_8 \) * \( 100_2 = 4_8 \) * \( 111_2 = 7_8 \) 4. Combine the octal digits: * \( (A7)_{16} = (247)_8 \) #### Example 3: Add \( (1011)_2 + (110)_2 \) ``` 1011 + 110 ------ ``` 1. Rightmost column: \( 1 + 0 = 1 \) 2. Second column from right: \( 1 + 1 = 0 \) carry \( 1 \) 3. Third column from right: \( 0 + 1 + \text{carry } 1 = 0 \) carry \( 1 \) 4. Leftmost column: \( 1 + \text{carry } 1 = 0 \) carry \( 1 \) Result: \( (10001)_2 \) #### Example 4: Add \( (37)_8 + (15)_8 \) ``` 37 + 15 ---- ``` 1. Rightmost column: \( 7 + 5 = 12 \). \( 12 \) in octal is \( 1 \times 8 + 4 \). So, write down \( 4 \) and carry \( 1 \). 2. Leftmost column: \( 3 + 1 + \text{carry } 1 = 5 \). Write down \( 5 \). Result: \( (54)_8 \) #### Example 5: Add \( (2A)_{16} + (1F)_{16} \) ``` 2A + 1F ---- ``` 1. Rightmost column: \( A + F = 10 + 15 = 25 \). \( 25 \) in hexadecimal is \( 1 \times 16 + 9 \). So, write down \( 9 \) and carry \( 1 \). 2. Leftmost column: \( 2 + 1 + \text{carry } 1 = 4 \). Write down \( 4 \). Result: \( (49)_{16} \) ### Exercises Answer the following questions to test your understanding. 1. Convert the following hexadecimal numbers to binary: a) \( (4B)_{16} \) b) \( (D0A)_{16} \) c) \( (1F3)_{16} \) 2. Convert the following hexadecimal numbers to octal: a) \( (5C)_{16} \) b) \( (1F)_{16} \) c) \( (2A8)_{16} \) 3. Perform the following binary additions: a) \( (1010)_2 + (111)_2 \) b) \( (11011)_2 + (1010)_2 \) c) \( (1111)_2 + (1)_2 \) 4. Perform the following octal additions: a) \( (62)_8 + (17)_8 \) b) \( (345)_8 + (123)_8 \) c) \( (77)_8 + (1)_8 \) 5. Perform the following hexadecimal additions: a) \( (3E)_{16} + (2A)_{16} \) b) \( (B5)_{16} + (C)_{16} \) c) \( (FF)_{16} + (1)_{16} \) ### Assignment Complete the following problems and submit them for grading. 1. A computer system represents colors using hexadecimal codes. If the code is \( (A3F)_{16} \), what is its binary equivalent? 2. Convert \( (FADE)_{16} \) to its octal representation. 3. You are given two binary numbers from a sensor reading: \( (110110)_2 \) and \( (10111)_2 \). What is their sum in binary? 4. In a legacy system, octal numbers are used. Calculate the sum of \( (176)_8 \) and \( (23)_8 \). 5. Network addresses sometimes use hexadecimal. If two segments are represented by \( (FF)_{16} \) and \( (2A)_{16} \), what is their sum in hexadecimal? ### Summary Today, we've expanded our understanding of number systems by mastering conversions and additions involving hexadecimal, binary, and octal. We learned that: * Hexadecimal to binary conversion is direct, with each hex digit mapping to a 4-bit binary sequence. * Hexadecimal to octal conversion is typically a two-step process: Hex to Binary, then Binary to Octal by grouping bits into threes. * Binary addition follows simple rules with a carry when the sum is \( 2 \) (i.e., \( 1+1 \)). * Octal addition involves carrying over when the sum in a column is \( 8 \) or more. * Hexadecimal addition involves carrying over when the sum in a column is \( 16 \) or more, remembering that A-F represent values 10-15. These operations are fundamental in computer science for understanding how data is represented and processed. Keep practicing to become proficient in these conversions and additions! ## Subtraction in a number system ### Introduction Welcome to this lesson on subtraction in various number systems! Building on our understanding of addition, we will now explore how to perform subtraction in binary, octal, and hexadecimal number systems. Subtraction is a fundamental arithmetic operation crucial for computer operations, data manipulation, and understanding how computers perform calculations at a low level. We will cover direct subtraction methods, including borrowing, and introduce complement methods (1's and 2's complement) which are particularly important in computer science for simplifying subtraction and handling negative numbers. ### Key Concepts #### 1. Review of Number Systems Before diving into subtraction, let's briefly recall the concept of a number system's base (radix) and place values. Each number system has a unique set of digits and rules for representing quantities. #### 2. Subtraction in the Decimal System (Base 10) Subtraction in the decimal system is familiar to us. When a digit in the minuend is smaller than the corresponding digit in the subtrahend, we 'borrow' from the digit to its left. A borrowed '1' from the next position to the left adds 10 to the current position. #### 3. Subtraction in the Binary System (Base 2) The binary system uses only two digits: 0 and 1. Subtraction follows these basic rules: * \( 0 - 0 = 0 \) * \( 1 - 0 = 1 \) * \( 1 - 1 = 0 \) * \( 0 - 1 = 1 \) with a borrow from the next more significant bit. ##### Direct Binary Subtraction with Borrowing When you need to subtract 1 from 0, you must borrow from the adjacent left column. When you borrow 1 from the next position in binary, it becomes \( 10_2 \) (which is \( 2_{10} \)) in the current position. ##### Subtraction Using 1's Complement This method is used primarily for binary subtraction and simplifies the process by converting subtraction into addition. The 1's complement of a binary number is obtained by inverting all its bits (changing 0s to 1s and 1s to 0s). **Steps:** 1. Determine the number of bits in the subtrahend and minuend. Pad with leading zeros if necessary to make them equal in length. 2. Find the 1's complement of the subtrahend. 3. Add the 1's complement of the subtrahend to the minuend. 4. **Check for an end-around carry:** * If there is a carry out (a '1' beyond the most significant bit), add this carry back to the least significant bit of the sum. The result is positive. * If there is no carry out, the result is negative. To get the magnitude, take the 1's complement of the sum (excluding any potential carry). Prepend a minus sign. ##### Subtraction Using 2's Complement The 2's complement method is widely used in computers because it eliminates the need for an end-around carry and simplifies the arithmetic logic unit (ALU) design. The 2's complement of a binary number is obtained by adding 1 to its 1's complement. **Steps:** 1. Determine the number of bits in the subtrahend and minuend. Pad with leading zeros if necessary to make them equal in length. 2. Find the 1's complement of the subtrahend. 3. Add 1 to the 1's complement to get the 2's complement of the subtrahend. 4. Add the 2's complement of the subtrahend to the minuend. 5. **Check for a carry out:** * If there is a carry out (a '1' beyond the most significant bit), discard it. The remaining bits form the positive result. * If there is no carry out, the result is negative. To get the magnitude, take the 2's complement of the sum. Prepend a minus sign. #### 4. Subtraction in the Octal System (Base 8) Octal subtraction is similar to decimal subtraction, but borrowing works differently. When you borrow 1 from the next position to the left, it adds 8 to the current position's value. #### 5. Subtraction in the Hexadecimal System (Base 16) Hexadecimal subtraction involves digits 0-9 and letters A-F (where A=10, B=11, C=12, D=13, E=14, F=15). When borrowing 1 from the next position, it adds 16 to the current position's value. It's often helpful to convert hexadecimal digits to their decimal equivalents temporarily for borrowing calculations. ### Vocabulary * **Minuend:** The number from which another number is subtracted. * **Subtrahend:** The number that is to be subtracted from the minuend. * **Difference:** The result of a subtraction operation. * **Borrow:** The action of taking value from a more significant digit's place to augment a less significant digit's place during subtraction when the latter is smaller than the subtrahend digit. * **Base (Radix):** The number of unique digits, including zero, used to represent numbers in a positional numeral system (e.g., 2 for binary, 10 for decimal). * **1's Complement:** In a binary number, obtained by inverting all bits (0s become 1s, 1s become 0s). * **2's Complement:** In a binary number, obtained by adding 1 to its 1's complement. Used extensively in computers to represent signed numbers and perform subtraction. * **End-around Carry:** A carry generated from the most significant bit position during 1's complement addition that is added back to the least significant bit position. ### Examples #### Example 1: Binary Subtraction (Direct Method) Subtract \( 011_2 \) from \( 101_2 \). ``` 101_2 - 011_2 ------- ``` **Step-by-step:** 1. Rightmost column: \( 1 - 1 = 0 \). 2. Middle column: \( 0 - 1 \). We need to borrow. Borrow 1 from the leftmost '1'. The leftmost '1' becomes '0'. The middle '0' becomes \( 10_2 \) (which is \( 2_{10} \)). So, \( 10_2 - 1_2 = 1_2 \). 3. Leftmost column: \( 0 - 0 = 0 \). Result: \( 010_2 \) #### Example 2: Binary Subtraction (Using 1's Complement) Subtract \( 011_2 \) from \( 101_2 \). **Step-by-step:** 1. Minuend: \( 101_2 \) 2. Subtrahend: \( 011_2 \) 3. 1's complement of subtrahend \( (011_2) \) is \( 100_2 \). 4. Add minuend and 1's complement of subtrahend: ``` 101 + 100 ----- 1001 ``` 5. There is a carry out (the leftmost '1'). Perform end-around carry (add it to the result): ``` 001 + 1 ----- 010 ``` Result: \( 010_2 \) #### Example 3: Binary Subtraction (Using 2's Complement) Subtract \( 011_2 \) from \( 101_2 \). **Step-by-step:** 1. Minuend: \( 101_2 \) 2. Subtrahend: \( 011_2 \) 3. 1's complement of subtrahend \( (011_2) \) is \( 100_2 \). 4. 2's complement of subtrahend is \( 100_2 + 1_2 = 101_2 \). 5. Add minuend and 2's complement of subtrahend: ``` 101 + 101 ----- 1010 ``` 6. There is a carry out (the leftmost '1'). Discard it. Result: \( 010_2 \) #### Example 4: Octal Subtraction Subtract \( 25_8 \) from \( 73_8 \). ``` 73_8 - 25_8 ------- ``` **Step-by-step:** 1. Rightmost column: \( 3 - 5 \). We need to borrow. Borrow 1 from '7' in the next column. The '7' becomes '6'. The '3' becomes \( 3 + 8 = 11_{10} \). So, \( 11 - 5 = 6_8 \). 2. Leftmost column: \( 6 - 2 = 4_8 \). Result: \( 46_8 \) #### Example 5: Hexadecimal Subtraction Subtract \( A7_{16} \) from \( F3_{16} \). ``` F3_{16} - A7_{16} --------- ``` **Step-by-step:** 1. Rightmost column: \( 3 - 7 \). We need to borrow. Borrow 1 from 'F' in the next column. The 'F' becomes 'E'. The '3' becomes \( 3 + 16 = 19_{10} \). So, \( 19_{10} - 7_{10} = 12_{10} \), which is \( C_{16} \). 2. Leftmost column: \( E - A \). (\( 14_{10} - 10_{10} = 4_{10} \)). So, \( 4_{16} \). Result: \( 4C_{16} \) ### Exercises Perform the following subtractions: 1. Binary Subtraction (Direct): a. \( 1101_2 - 0110_2 \) b. \( 1000_2 - 0011_2 \) 2. Binary Subtraction (using 1's Complement): a. \( 1110_2 - 0101_2 \) b. \( 0101_2 - 1011_2 \) (for this one, you should get a negative result) 3. Binary Subtraction (using 2's Complement): a. \( 11011_2 - 10010_2 \) b. \( 1010_2 - 1101_2 \) (for this one, you should get a negative result) 4. Octal Subtraction: a. \( 52_8 - 37_8 \) b. (705)_8 - (126)_8 5. Hexadecimal Subtraction: a. \( C9_{16} - 3A_{16} \) b. \( 2F4_{16} - 1B5_{16} \) ### Assignment 1. Subtract \( 10110_2 \) from \( 11001_2 \) using: a. Direct binary subtraction. b. 1's complement method. c. 2's complement method. Compare your results. 2. Perform the following mixed-system subtractions (convert if necessary): a. \( (100)_{10} - (110011)_2 \) (Express answer in decimal). b. \( (AB)_{16} - (57)_8 \) (Express answer in hexadecimal). 3. A computer system represents numbers using 8 bits. If a number is represented as \( (01010110)_2 \), what is the 2's complement of this number? If we want to subtract this number from \( (10001000)_2 \) using 2's complement arithmetic, show the steps. 4. Explain, in your own words, why 2's complement subtraction is often preferred over 1's complement subtraction in digital circuits. ### Summary In this lesson, we explored various methods for performing subtraction across different number systems. We started with the familiar concept of direct borrowing in decimal, extending it to binary, octal, and hexadecimal systems. For binary numbers, we learned two powerful techniques: 1's complement and 2's complement subtraction. The 1's complement method involves an end-around carry, while the 2's complement method simplifies subtraction to addition and is widely used in computer hardware due to its efficiency and ability to handle signed numbers naturally. Mastering these techniques is fundamental for understanding digital arithmetic and how computers process numerical data. ## Integration activities ### Introduction Welcome to this lesson on integrating operations on number systems! In previous lessons, you've learned about different number systems like decimal, binary, octal, and hexadecimal, as well as how to convert between them and perform basic arithmetic operations. This lesson will bring all these concepts together. We will review key principles, practice various conversions, and apply arithmetic operations, especially in binary, to solidify your understanding. Mastering these operations is crucial for understanding how computers process and store data. ### Key Concepts #### 1. Review of Number Systems Computer systems represent information using various number systems. Each system is defined by its base or radix. * **Decimal (Base-10):** The system we use daily, employing ten unique digits (0-9). The position of a digit determines its value, which is a power of 10. * **Binary (Base-2):** The fundamental system for computers, using only two digits (0 and 1). Each digit is called a bit. Computers use binary because it's easy to represent with electrical signals (on/off, high/low voltage). * **Octal (Base-8):** Uses eight unique digits (0-7). It's often used as a compact way to represent binary numbers, as three binary digits can represent one octal digit. * **Hexadecimal (Base-16):** Uses sixteen unique digits (0-9 and A-F, where A=10, B=11, C=12, D=13, E=14, F=15). It's widely used in computing for memory addresses, color codes, and other data representations because four binary digits can represent one hexadecimal digit. #### 2. Conversions Between Number Systems Being able to convert numbers between different bases is a fundamental skill in computer science. ##### a. Decimal to Other Bases (Binary, Octal, Hexadecimal) To convert a decimal number to another base, use the division method: * Repeatedly divide the decimal number by the target base. * Record the remainder at each step. * The remainders, read from bottom to top, form the number in the new base. ##### b. Other Bases (Binary, Octal, Hexadecimal) to Decimal To convert a number from any base to decimal, use the sum of powers method: * Multiply each digit by its corresponding positional weight (base raised to the power of its position, starting from 0 from the right). * Sum all the products. ##### c. Binary to Octal and Hexadecimal These conversions are straightforward due to the relationship between their bases: * **Binary to Octal:** Group binary digits in sets of three, starting from the right. Convert each group into its octal equivalent. * **Binary to Hexadecimal:** Group binary digits in sets of four, starting from the right. Convert each group into its hexadecimal equivalent. ##### d. Octal and Hexadecimal to Binary * **Octal to Binary:** Convert each octal digit into its 3-bit binary equivalent. * **Hexadecimal to Binary:** Convert each hexadecimal digit into its 4-bit binary equivalent. ##### e. Conversions via Binary (Octal to Hexadecimal, Hexadecimal to Octal) When converting between Octal and Hexadecimal, it's often easiest to convert to Binary first: * **Octal to Hexadecimal:** Octal \( \rightarrow \) Binary \( \rightarrow \) Hexadecimal. * **Hexadecimal to Octal:** Hexadecimal \( \rightarrow \) Binary \( \rightarrow \) Octal. #### 3. Arithmetic Operations (Binary Focus) ##### a. Binary Addition Binary addition follows simple rules, similar to decimal addition with carries: * \( 0 + 0 = 0 \) * \( 0 + 1 = 1 \) * \( 1 + 0 = 1 \) * \( 1 + 1 = 0 \) (with a carry of 1 to the next position) ##### b. Binary Subtraction (Using 2's Complement) Binary subtraction is commonly performed using the 2's complement method, especially in digital circuits, as it simplifies the hardware required for both addition and subtraction. * **1's Complement:** Invert all bits (0 becomes 1, 1 becomes 0). * **2's Complement:** Add 1 to the 1's complement of the number. * **Subtraction Process:** To calculate \( A - B \): 1. Find the 2's complement of B (the subtrahend). 2. Add A to the 2's complement of B: \( A + (\text{2's complement of B}) \). 3. If there is an end-around carry, discard it. The remaining bits are the result. 4. If there is no end-around carry, the result is negative, and its value is the 2's complement of the sum. ##### c. Binary Multiplication Binary multiplication is similar to decimal multiplication, involving shifting and adding: * Multiply the multiplicand by each digit of the multiplier. * If the multiplier digit is 1, write down the multiplicand. * If the multiplier digit is 0, write down all zeros. * Shift the results left for each position. * Add the partial products. ##### d. Binary Division Binary division is similar to long division in decimal: * Compare the divisor with the dividend's leftmost digits. * If the divisor is smaller, place a 1 in the quotient and subtract the divisor from the dividend. * Bring down the next digit and repeat. * If the divisor is larger, place a 0 in the quotient and bring down the next digit. ### Vocabulary * **Base/Radix:** The number of unique digits or symbols used in a number system. * **Binary:** A base-2 number system, using digits 0 and 1. * **Octal:** A base-8 number system, using digits 0-7. * **Decimal:** A base-10 number system, using digits 0-9. * **Hexadecimal:** A base-16 number system, using digits 0-9 and A-F. * **Bit:** A binary digit (0 or 1), the smallest unit of data in computing. * **Nibble:** A group of four bits. * **Byte:** A group of eight bits. * **LSB (Least Significant Bit):** The rightmost bit in a binary number, representing the smallest positional value. * **MSB (Most Significant Bit):** The leftmost bit in a binary number, representing the largest positional value. * **1's Complement:** The result of inverting all bits of a binary number. * **2's Complement:** The 1's complement of a binary number plus one, used for representing negative numbers and performing subtraction. ### Examples #### 1. Mixed Conversion Convert \( (150)_{10} \) to binary, then to octal, then to hexadecimal. **Step 1: Decimal to Binary** \( 150 \div 2 = 75 \) remainder 0 \( 75 \div 2 = 37 \) remainder 1 \( 37 \div 2 = 18 \) remainder 1 \( 18 \div 2 = 9 \) remainder 0 \( 9 \div 2 = 4 \) remainder 1 \( 4 \div 2 = 2 \) remainder 0 \( 2 \div 2 = 1 \) remainder 0 \( 1 \div 2 = 0 \) remainder 1 Reading remainders from bottom to top: \( (10010110)_2 \) **Step 2: Binary to Octal** Group in 3s from right: \( 10 \ 010 \ 110 \) Convert each group: \( 2 \ 2 \ 6 \) Result: \( (226)_8 \) **Step 3: Binary to Hexadecimal** Group in 4s from right: \( 1001 \ 0110 \) Convert each group: \( 9 \ 6 \) Result: \( (96)_{16} \) #### 2. Binary Addition Add \( (1011)_2 \) and \( (1101)_2 \) \[ \begin{array}{r} 1011_2 \\ +\ 1101_2 \\ \hline 11000_2 \end{array} \] * 1 + 1 = 0 carry 1 * 1 + 0 + (carry 1) = 0 carry 1 * 0 + 1 + (carry 1) = 0 carry 1 * 1 + 1 + (carry 1) = 1 carry 1 #### 3. Binary Subtraction (using 2's Complement) Subtract \( (0101)_2 \) from \( (1010)_2 \) (i.e., \( 1010 - 0101 \)) **Step 1: Find 2's complement of \( (0101)_2 \)** * 1's complement of \( (0101)_2 \) is \( (1010)_2 \) * Add 1: \( (1010)_2 + (0001)_2 = (1011)_2 \) (2's complement) **Step 2: Add \( (1010)_2 \) to \( (1011)_2 \)** \[ \begin{array}{r} 1010_2 \\ +\ 1011_2 \\ \hline 10101_2 \end{array} \] **Step 3: Discard the end-around carry (the leftmost 1)** The result is \( (0101)_2 \). (Which is \( 10 - 5 = 5 \) in decimal). ### Exercises 1. Convert the following numbers to their indicated bases: a. \( (237)_{10} \) to Binary b. \( (A5F)_{16} \) to Decimal c. \( (1101101)_2 \) to Octal d. \( (724)_8 \) to Hexadecimal e. \( (101110111)_2 \) to Hexadecimal 2. Perform the following binary arithmetic operations: a. \( 1101_2 + 1011_2 \) b. \( 10010_2 - 01101_2 \) (using 2's complement) c. \( 110_2 \times 101_2 \) 3. A computer stores an 8-bit number as \( (11001011)_2 \). If this represents a signed number using 2's complement, what is its decimal value? ### Assignment 1. Convert the following numbers: a. \( (405.625)_{10} \) to Binary (include the fractional part). b. \( (3FA.C)_{16} \) to Octal. 2. Perform the following binary operations: a. Add \( (11101.11)_2 \) and \( (101.01)_2 \). b. Subtract \( (01110)_2 \) from \( (10100)_2 \) using the 2's complement method. c. Multiply \( (11011)_2 \) by \( (101)_2 \). 3. In digital image processing, colors are often represented using hexadecimal codes (e.g., #RRGGBB). If a specific shade of blue has a hexadecimal code \( (0000FF)_{16} \), what is its binary representation? How many bits are used for this color? ### Summary In this lesson, we have revisited and integrated our knowledge of number systems and their operations. We covered the four main number systems (decimal, binary, octal, hexadecimal), their importance in computing, and systematic methods for converting numbers between any of these bases. We also practiced binary arithmetic operations, with a special focus on binary addition and subtraction using the efficient 2's complement method. A strong grasp of these concepts is fundamental for understanding computer architecture, data representation, and programming at a low level.

Quiz du chapitre

16 questions — vérifie chaque réponse pour voir l'explication.

  1. 1. Which of the following number systems uses only two distinct digits, 0 and 1?
  2. 2. What is the base or radix of the octal number system?
  3. 3. In the hexadecimal number system, which letter represents the decimal value 12?
  4. 4. What is the decimal equivalent of the binary number (1101)_2?
  5. 5. Convert the octal number (45)_8 to its decimal equivalent.
  6. 6. What is the decimal value of the hexadecimal number (2F)_16?
  7. 7. Convert the decimal number 27 to its binary equivalent.
  8. 8. What is 75 in decimal converted to an octal number?
  9. 9. Convert the decimal number 50 to its hexadecimal equivalent.
  10. 10. Which number system is most commonly used by humans for everyday calculations?
  11. 11. The positional value of the digit '1' in the binary number (1000)_2 is:
  12. 12. What is the largest single digit in the octal number system?
  13. 13. Convert (1A7)_16 to its decimal equivalent.
  14. 14. Which of the following is NOT a valid digit in the binary number system?
  15. 15. Convert the decimal number 100 to its binary representation.
  16. 16. What is the decimal equivalent of the octal number (27)_8?