Chapter 1 Preliminaries This chapter discusses the major classes of programming languages and the relationship among them. It also discusses the binary and the hexadecimal number systems which are used in most computer systems, including computer systems based on the Intel X-86 processors. 1.1 Classes of Programming Languages A programmer instructs a computer to perform a task or to solve a problem by specifying the step-by-step operations that the computer must execute in order to perform that task, or to solve that problem. The specification of these step-by-step operations is done in a programming language, and is referred to as a program. In general, a programming language belongs to one of the two major classes of programming language, High-level languages and Low-level languages. Examples of high-level languages are Pascal, PL/1, C/C++, BASIC, FORTRAN, COBOL, Java,..., etc. Low-level languages are machine languages and their corresponding assembly languages. Machine Languages A machine language program consists of instructions and data represented as sequences of binary digits (or bits), 0's and 1's. 1
2 A machine language instruction specifies a fundamental operation that the computer is capable of carrying out. It consists in general of two major parts: the operation code and the operand as illustrated in section a of Figure 1.1. The operation code also referred to as opcode, specifies the operation to be carried out by the computer, and the operand specifies the data, or the location (inside of the computer) of the data on which the operation is to be carried out. Figure 1.1 Machine/Assembly language Instruction a) Machine language Instruction General Format Opcode Operand b) Intel 8086 Processor Machine/Assembly Language Instruction 1. Instruction in binary: 10000011 1100001000000111 2. Instruction in hexadecimal: 83 C207 3. Instruction in assembly language: SUB DX, 7 Each type of computer has a collection of machine language instructions called instruction set. The instruction set of a computer is referred to as its machine language and depends on the computer s processor. Two different types of computer have different instruction sets, and a program is executed by a computer only if it is written in its machine language. For example, a program written for the IBM PC and compatible computers can not be executed by an Apple Macintosh computer. An instruction for the IBM PC and compatible computers is provided in part1 of section b) of Figure 1.1. The opcode of this instruction is 10000011, and its operand is 1100001000000111. It says to subtract the integer value 7 from the integer value in register DX, and to place the result of the operation back into register DX.
It is difficult for most humans to process instructions and data specified in binary because of their length and the many possibilities to make mistakes: for these reasons, machine language instructions and data are often specified in hexadecimal (base 16) or octal (base 8) number systems. These number systems provide more compact ways to write binary information. The above instruction is also specified in hexadecimal in part 2 of section b) of Figure 1.1. 3 Assembly Languages Even with the hexadecimal or the octal number system notation, it is extremely difficult to write programs in a machine language: it is particularly difficult to remember the opcodes of instructions and to specify the operands of instructions. Another language called assembly language was created to allow programmers to use symbols instead of the digits of a number system to write the instructions of a program. There is an assembly language for each machine language in such a way that an assembly language instruction is the symbolic representation of a machine language instruction. For example, in section b) of Figure 1.1, the assembly language instruction that corresponds to the machine language instruction provided in parts1 and 2 is provided part 3. Since a program is executed by a computer only if it is written in its machine language, a program written in the assembly language of a computer most first be translated into machine language before it can be executed by that computer. For each type of computer, there is a system program called assembler that translates programs written in the assembly language of that computer into its machine language. The assembler takes as input a program in assembly language and produces as output a program in machine language. High-Level Languages Writing programs in a low-level (machine or assembly) language requires the programmer to know the detailed structure of the underlying computer. This knowledge of the computer makes it possible to write more efficient programs that better use the system resources. However, programs written in low-level languages lack the flexibility and the portability of high-level language programs.
4 A high-level language program reflects the structure of an algorithm, and does not depend on the structure of any particular type of computer; it may be executed on any computer, and a high-level language programmer does not need to know the structure of any particular computer. However, for a high-level language program to be executed by a computer, it must first be translated into the machine language of that computer. A compiler is a system program that translates high-level language programs into machine language. For each type of computer, there is a compiler for each high-level language. For examples, the C/C++ compiler for the IBM PC and compatible computers, the C/C++ compiler for the Sun Microsystem computers, the Java compiler for the IBM PC and compatible computers, the Java compiler for the Apple Macintosh computers,...etc. Compilers, assemblers, and other system software that are necessary for the development of programs are discussed in chapter 5. Exercise 1.1 Part I Fill in the blanks with the most appropriate answers. 1. A is the specification in a programming language of the step-bystep operations that the computer must execute in order to perform a task or to solve a problem. 2. The two major classes of programming language are: and. 3. Low-level languages are and. 4. A program in language consists of instructions and data represented as sequences of binary digits (or bits), 0's and 1's. 5. A specifies a fundamental operation that the computer is capable of carrying out. 6. A program is executed by a computer only if it is written in. 7. The of an instruction specifies the operation to be carried out by the computer. 8. The of an instruction specifies the data, or the location (inside of the computer) of the data on which the operation is to be carried out. 9. An is a system program that takes as input a program in assembly language and produces as output a program in machine language. 10. A is a system program that takes as input a program in a high-level language and produces as output a program in machine language.
5 Part II Answer by True or False. 1. Each type of computer has a collection of machine language instructions called instruction set that is defined by the computer designer. True False 2. A machine language program for IBM PC and compatible computers can also be executed by an Apple Macintosh computer. True False 3. Binary information may also be specified in hexadecimal or octal. True False 4. An assembly language instruction corresponds exactly to one machine language instruction. True False 5. A computer can execute a program in assembly language. True False 6. Some computers do not have a machine language instruction set. True False 7. In order to write programs in a machine or assembly language, the programmer must know the structure of the corresponding computer. True False 8. Some computers can execute programs written in C++. True False 9. The same C++ compiler may be used to translate a C++ program into the machine languages of IBM PC and compatible computers and Apple Macintosh computers. True False 10. In order to write programs in some high-level languages, programmers must know the structure of the computer on which the program will be executed. True False 1.2 Number Systems In our daily activities, we use the decimal number system to represent numeric data. In this system also known as the number system of radix 10 or base 10, ten symbols (the digits 0 through 9) are used to represent positive integers. It is a positional number system, because the value that corresponds to each digit in a number depends on its position within that number: each digit represents a multiple of a power of 10 as in the following example: 3052 = 3 x 1000 + 0 x 100 + 5 x 10 + 2 x 1 3 2 1 0 = 3 x 10 + 0 x 10 + 5 x 10 + 2 x 10 Unlike what we do in our daily activities, information inside a digital computer is represented as a sequence of 0's and 1's. That means, computers use the binary (or base 2) number system to represent information. However, binary information is difficult to process by most people, because of their length, and the many possibilities to make mistakes.
6 It is more convenient to express binary information in a more compact form by using the hexadecimal (base 16) number system or the octal (base 8) number system. For example, the binary number 110001101011 is expressed in octal as 6153 and in hexadecimal as C6B. In the following sections, we discuss the binary and the hexadecimal number systems and also show how they are related to the decimal system, and to each other. Binary Integers In binary (or base 2), two digits, 0 and 1, called binary digits or bits are used to represent positive integers. A binary integer is a sequence of the bits 0 and 1 in such a way that the value that corresponds to each digit depends on its position within the number. Examples of binary integers are 02, 12, 102, 112, 1010, and 11011010110. 2 2 The binary integer 11010012 is read: "one, one, zero, one, zero, zero, one, base 2." Subscript 2 is added to the sequence of bits in order to indicate that it is a binary number. Alternatively, the letter B or b may also be appended to it as in 1101001B, or 1101001b. The decimal value of the n-digit binary integer b n-1 b n-2... b 1 b 0 is computed as: n-1 n-2 1 0 b n-1 x 2 + b n-2 x 2 +... + b 1 x 2 + b 0 x 2 That means, each position in a binary integer corresponds to a power of 2 as 0 1 follows: the first position to the right corresponds to 2 or 1, the next to 2,..., etc. Example 1.1 illustrates the conversion process from binary to decimal. Example 1.1 Conversion from Binary to Decimal Convert the binary integers 02, 12, 102, 10002, and 110101112 to decimal. 0 a) 02 = 0x2 = 0 0 b) 1 = 1x2 = 1 2 1 0 c) 10 = 1x2 + 0x2 = 2 2 3 2 1 0 d) 1000 = 1x2 + 0x2 + 0x2 + 0x2 = 8 2 e) 11010111 = 1x2 + 1x2 + 0x2 + 1x2 + 0x2 + 1x2 + 1x2 + 1x2 2 7 6 5 4 3 2 1 0 = 128 + 64 + 16 + 4 + 2 + 1 = 215
7 Exercise 1.2 Convert the following binary integers to decimal: a. 1012, b. 112 c. 1102 d. 10110012 e. 101101102. Conversion from Decimal to Binary Two methods are commonly used to convert a positive decimal integer to binary. The first method uses repeated divisions by two, whereas the second uses the decomposition of a positive decimal integer into a sum of powers of two. First method The binary representation b n-1 b n-2... b 1 b 0 of a positive decimal integer m is obtained as follows: 1. Divide the integer m by 2, and 2. As long as the new quotient is not zero, divide it by 2. b 0 is the first remainder, b 1 the second,..., and b n-1 is the last remainder. This procedure is illustrated in Example 1.2. Example 1.2 Conversion from Decimal to Binary (First Method) Convert the decimal integers 8 and 53 to binary using the first conversion method. 8 2 = 4 with remainder 0 4 2 = 2 with remainder 0 2 2 = 1 with remainder 0 1 2 = 0 with remainder 1 810 = 10002 53 2 = 26 with remainder 1 26 2 = 13 with remainder 0 13 2 = 6 with remainder 1 6 2 = 3 with remainder 0 3 2 = 1 with remainder 1 1 2 = 0 with remainder 1 5310 = 1101012
8 Exercise 1.3 Convert the following decimal integers to binary using the first conversion method: a. 10 b. 28 c. 523 d. 1342 e. 3035 Second Method The binary representation b n-1 b n-2... b 1 b 0 of a positive decimal integer m is obtained as follows: 1. Find all powers of 2 that add up to m. i 2. set b i to 1 if 2 is one of the powers, otherwise set it to 0. Use Table 1.1 to find all powers of two that add up to a decimal integer m as follows: 1. Find the highest power of two less than or equal to m. 2. Subtract it from m. 3. Repeat steps 1 and 2 for the new difference until you obtain a difference of 0. This procedure is illustrated in Example 1.3. Example 1.3 Conversion from Decimal to Binary (Second Method) Convert the decimal integers 47 and 2840 to binary using the second conversion method: 47-32 = 15 15-8 = 7 7-4 = 3 3-2 = 1 1-1 = 0 2840-2048 = 792 792-512 = 280 280-256 = 24 24-16 = 8 8-8 = 0 47 = 32 + 8 + 4 + 2 +1 5 3 2 1 0 = 2 + 2 + 2 + 2 + 2 = 101111 2 2840 = 2048 + 512 + 256 + 16 + 8 11 9 8 4 3 = 2 + 2 + 2 + 2 + 2 = 101100011000 2
9 Exercise 1.4 Convert the following decimal integers to binary using the second conversion method: a. 28 b. 523 c. 2045 d. 5,753 e. 8, 234 Hexadecimal Integers In hexadecimal (also known as base 16), sixteen digits (0 through 9 and A, B, C, D, E and F) are used to represent positive integers. The values of the digits A, B, C, D, E, and F are respectively 10, 11, 12, 13, 14, and 15. An hexadecimal integer is a sequence of these digits arranged in such a way that the value that each digit within the sequence represents, depends on its position in the sequence. The hexadecimal integer 2AF6h is read: " two, 'A', 'F', six, in hexadecimal (or base 16)." To specify that a number is an hexadecimal number, we usually append a lowercase or uppercase H to it. Alternatively, the subscript 16 may also be appended to it as in 2AF6. The decimal value of the n-digit hexadecimal integer h n-1 h n-2... h 1 h 0 is computed as follows: n-1 n-2 1 0 h n-1 x 16 + h n-2 x 16 +... + h 1 x 16 + h 0 x 16 Each position in an hexadecimal integer corresponds to a power of 16, 0 1 starting with 16 or 1 to the right, then 16,..., etc. Example 1.4 illustrates the conversion procedure from hexadecimal to decimal. Multiples of powers of 16 are provided in Table 1.2. Each column in Table 1.2 corresponds to a 0 7 power of 16, starting with 16 to the right, up to 16 to the left. In each column, the decimal integer that corresponds to an hexadecimal digit is the multiple of power of 16 in that column that corresponds to that digit. For 2 example, 5x16 is 1280, because in column 3, 1280 corresponds to digit 5. 16
10 Example 1.4 Conversion from Hexadecimal to Decimal Convert the hexadecimal integers 10h, 530h, and A05Fh to decimal. 1 0 a) 10h = 1 x 16 + 0 x 16 = 16 2 1 0 b) 530h = 5x16 + 3x16 + 0x16 = 1,280 + 48 + 0 = 1,328 3 2 1 0 c) A05Fh = 10x16 + 0x16 + 5x16 + 15x16 = 40,960 + 0 + 80 + 15 = 41,055 Exercise 1.5 Convert the following hexadecimal integers to decimal: a. 1Ah b. 20Eh c. 412h d. 2BC5 e. F50A Conversion from Decimal to Hexadecimal The procedures to convert from decimal to hexadecimal are very similar to those used to convert from decimal to binary: the first method uses repeated divisions by sixteen, whereas the second uses the decomposition of a positive integer into a sum of multiples of powers of sixteen. First method The hexadecimal representation, h n-1 h n-2... h 1 h 0, of a positive decimal integer m is obtained as follows: 1. Divide the decimal integer m by 16, and 2. As long as the new quotient is not zero, divide it by 16. 0 1 n-1 h is the first remainder, h the second,..., and h the last remainder. This procedure is illustrated in Example 1.5.
11 Example 1.5 Conversion from Decimal to Hexadecimal (First Method) Convert the decimal integers, 18, 32, and 1213 to hexadecimal. a) 18 16 = 1 with remainder 2 1 16 = 0 with remainder 1 1810 = 1216 b) 32 16 = 2 with remainder 0 0 16 = 0 with remainder 0 3210 = 2016 c) 1213 16 = 75 with remainder 13 ( D ) 75 16 = 4 with remainder 11 ( B ) 4 16 = 0 with remainder 4 121310 = 4BD16 Exercise 1.6 Convert the following decimal integers to hexadecimal using the first conversion method: a. 28 b. 523 c. 1342 d. 3035 e. 5753 Second Method n-1 n-2 1 0 The hexadecimal representation, h h... h h, of a positive decimal integer m is obtained as follows:
12 1. Find all multiples of powers of 16 that add up to m. i 2. If 16 is one of the powers in this decomposition, set h i to its coefficient; otherwise set it to 0. Use Table 1.3 to find all multiples of powers of sixteen that add up to a decimal integer m as follows: 1. Find the largest multiple of a power of sixteen less than or equal to m. 2. Subtract it from m. 3. Repeat steps 1 and 2 for the new difference until you obtain a difference of 0. This procedure is illustrated in Example 1.6. Example 1.6 Conversion from Decimal to Hexadecimal (Second Method) Convert the decimal integers 108 and 61499 to hexadecimal. 108-96 = 12 12-12 = 0 108 = 96 + 12 1 0 = 6 x 16 + 12 x 16 = 6Ch 61499-61440 = 59 59-48 = 11 11-11 = 0 61499 = 61440 + 48 + 11 3 1 0 = F x 16 + 3 x 16 + B x 16 = F03B 16 Exercise 1.7 Convert the following decimal integers to hexadecimal using the second conversion method: a. 28 b. 523 c. 1342 d. 5753 e. 15753
13 Binary and Hexadecimal Conversions The conversion from binary to hexadecimal, or from hexadecimal to binary is done by observing that each of the 16 hexadecimal digits corresponds to one of the 4-bit integers as follows: 0000 = 0 0100 = 4 1000 = 8 1100 = C 0001 = 1 0101 = 5 1001 = 9 1101 = D 0010 = 2 0110 = 6 1010 = A 1110 = E 0011 = 3 0111 = 7 1011 = B 1111 = F To convert a sequence of bits to hexadecimal, start from the right of the sequence and replace every four consecutive bits in the sequence with its corresponding hexadecimal digit. Additional 0's may be added to the left of the sequence if necessary. An hexadecimal integer is converted to binary by replacing each hexadecimal digit in the number with its corresponding 4-bit integer. These two conversion procedures are illustrated in Example 1.7. Example 1.7 Binary and Hexadecimal Conversions a) Convert the binary integers 1102, 1010102, and 11101001100002 to hexadecimal. 1102 = 6h 101010 = 0010 1010 = 2Ah 2 2 A 1110100110000 = 1 1101 0011 0000 = 1D30h 2 1 D 3 0 b) Convert the hexadecimal numbers 35h and A0B4h to binary. 35 = 0011 0101 = 00110101 2 3 5 A0B4h = 1010 0000 1011 0100 = 1010 00001011 0100 2 A 0 B 4
14 Exercise 1.8 1. Convert the following binary integers to hexadecimal: a. 1012 b. 1011102 c. 11010001101012 2. Convert the following hexadecimal integers to binary: a. 27h b. 3A0h c. C14Dh Arithmetic Operations The rules that apply to arithmetic in binary and hexadecimal number systems are the same as those that apply to arithmetic in the decimal number system. However, when you perform these operations, you must remember that the binary integer 10b is 2 in decimal, and that the hexadecimal integer 10h is 16 in decimal. Binary Addition We first introduce the addition of two bits as follows: 0 0 1 1 + 0 + 1 + 0 + 1 0 1 1 10 You add two binary integers with more than one bit by following the same rules that you use for decimal addition: add individual bits as specified above, and if a carry is generated in any position, you add it to the position immediately to the left. Example 1.8 illustrates the binary addition. Example 1.8 Addition of Unsigned Binary Integers 1 1 1 1 1 1 1 1 a. 1 0 1 1 b. 1 0 1 0 1 1 0 1 c. 1 0 1 0 1 1 0 1 1 0 + 1 0 0 + 1 0 1 1 1 0 + 1 0 1 0 1 0 1 1 0 1 1 1 1 1 1 1 0 1 1 0 1 1 1 0 1 0 1 1 0 0 0 1 1
15 Exercise 1.9 Perform the following operations on binary integers: a. 1 0 1 0 b. 1 0 1 0 0 1 1 0 c. 1 1 1 0 1 1 0 1 0 1 + 1 0 1 + 1 0 1 1 0 1 + 1 0 1 0 1 0 1 1 1 1 Hexadecimal Addition You add two hexadecimal digits by first converting them to decimal, performing the addition in decimal, and then converting the result back to hexadecimal. For example, to add Dh + Ah, we perform the addition 13 + 10. The result is 23, which corresponds to the hexadecimal integer 17h. Therefore, Dh + Ah equals 17h. Table 1.2 illustrates the addition of hexadecimal digits. You add two hexadecimal integers with more than one digit by following the same rules that you use for binary addition: add individual hexadecimal digits as specified above, and if a carry is generated in any position, you add it to the position immediately to the left. Example 1.9 illustrates the addition in hexadecimal. Example 1.9 Addition of Hexadecimal Integers 1 1 1 1 1 a. 1 0 B 7 b. 6 A 8 9 c. 5 4 F 9 E + 5 2 5 + 7 5 A 0 + D C 6 3 A 1 5 D C E 0 2 9 1 3 1 5 D 8
16 Exercise 1.10 Perform the following addition on hexadecimal integers: a. 1 A 0 6 b. 6 A F 5 c. 4 F 4 B + 5 C 3 + 7 5 3 6 + D E 9 A Subtraction of Binary and Hexadecimal Integers Subtracting binary or hexadecimal integers follows the same rules as those for decimal integers subtraction. In particular, before you can subtract a larger digit from a smaller one, you must borrow a 1 from the digit immediately to the left; and a borrowed digit becomes 10 in the current position. You subtract an hexadecimal digit from another one by first converting them to decimal, perform the subtraction in decimal, and then convert the result back to hexadecimal. Example 1.10 and Example 1.11 illustrate the subtraction of binary integers, and hexadecimal integers respectively. Example 1.10 Subtracting Binary Integers 0 0 0 1 1 1 1 1 a. 1 0 1 1 0 1 b. 1 0 1 0 1 1 0 c. 1 0 0 0 1-1 0 0 1-1 1 0 1-1 0 1 1 1 0 0 1 0 0 1 0 0 1 0 0 1 1 1 0
17 Exercise 1.11 Perform the following operations on binary integers: a. 1 1 0 1 1 b. 1 0 1 1 1 0 1 0 c. 1 1 1 0 1 1 0 1 0 1-1 0 0 1-1 0 1 1 0 1-1 0 1 0 1 0 1 1 1 1 Example 1.11 Subtracting Hexadecimal Integers 0 4 D F F 1 1 1 a. 3 D 5 F b. 1 0 C 5 2 c. E 0 0 B 7-2 4 A - A 2 1 7-8 D 4 3 B 1 5 6 A 3 B D F 7 E 3 Exercise 1.12 Perform the following subtraction on hexadecimal integers: a. 1 A 0 6 b. 6 A F 5 c. 4 F 4 B + 5 C 3 + 7 5 3 6 + D E 9 A
18 Multiplication and Division of Binary Integers You multiply or divide binary integers the same way you multiply or divide decimal integers. Example 1.12 illustrates the multiplication and the division of binary integers. Example 1.12 Multiplying and Dividing Unsigned Binary Integers a) 1 0 1 1 0 1 1 x 1 1 0 1 ------------------------------ 1 0 1 1 0 1 1 0 0 0 0 0 0 0 1 0 1 1 0 1 1 1 0 1 1 0 1 1 ---------------------------------------- 1 0 0 1 0 0 1 1 1 1 1 b) In the binary division of 1110101 by 110, the quotient is 10011 and the remainder is 11: 1 0 0 1 1 110 ) 1 1 1 0 1 0 1-1 1 0 1 0 1 0-1 1 0 1 0 0 1-1 1 0 1 1 Exercise 1.13 Perform the following operations on binary integers: a. 1 0 1 1 0 1 1 x 1 0 1 1 b. 1 0 1 1 0 0 1 1 0 1 1 1 0 1
19 Table 1.1 Powers of two n n n 2 n 2 0 1 8 256 1 2 9 512 2 4 10 1024 3 8 11 2048 4 16 12 4096 5 32 13 8,192 6 64 14 16,384 7 128 15 32,768 16 65,536 Table 1.2 Addition of Hexadecimal Digits + 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 0 1 2 3 4 5 6 7 8 9 A B C D E F 1 1 2 3 4 5 6 7 8 9 A B C D E F 10 2 2 3 4 5 6 7 8 9 A B C D E F 10 11 3 3 4 5 6 7 8 9 A B C D E F 10 11 12 4 4 5 6 7 8 9 A B C D E F 10 11 12 13 5 5 6 7 8 9 A B C D E F 10 11 12 13 14 6 6 7 8 9 A B C D E F 10 11 12 13 14 15 7 7 8 9 A B C D E F 10 11 12 13 14 15 16 8 8 9 A B C D E F 10 11 12 13 14 15 16 17 9 9 A B C D E F 10 11 12 13 14 15 16 17 18 A A B C D E F 10 11 12 13 14 15 16 17 18 19 B B C D E F 10 11 12 13 14 15 16 17 18 19 1A C C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B D D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C E E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D F F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E
20 Table 1.3 Hexadecimal-Decimal conversion Table Hex Dec Hex Dec Hex Dec Hex Dec Hex Dec Hex Dec Hex Dec Hex Dec 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 268,435,456 1 16,777,216 1 1,048,576 1 65,536 1 4,096 1 256 1 16 1 1 2 536,870,912 2 33,554,432 2 2,097,152 2 131,072 2 8,192 2 512 2 32 2 2 3 805,306,368 3 50,331,648 3 3,145,728 3 196,608 3 12,288 3 768 3 48 3 3 4 1,073,741,824 4 67,108,864 4 4,194,304 4 262,144 4 16,384 4 1,024 4 64 4 4 5 1,342,177,280 5 83,886,080 5 5,242,880 5 327,680 5 20,480 5 1,280 5 80 5 5 6 1,610,612,736 6 100,663,296 6 6,291,456 6 393,216 6 24,576 6 1,536 6 96 6 6 7 1,879,048,192 7 117,440,512 7 7,340,032 7 458,752 7 28,672 7 1,792 7 112 7 7 8 2,147,483,648 8 134,217,728 8 8,388,608 8 524,288 8 32,768 8 2,048 8 128 8 8 9 2,415,919,104 9 150,994,944 9 9,437,184 9 589,824 9 36,864 9 2,304 9 144 9 9 A 2,684,354,560 A 167,772,160 A 10,485,760 A 655,360 A 40,960 A 2,560 A 160 A 10 B 2,952,790,016 B 184,549,376 B 11,534,336 B 720,896 B 45,056 B 2,816 B 176 B 11 C 3,221,225,472 C 201,326,592 C 12,582,912 C 786,432 C 49,152 C 3,072 C 192 C 12 D 3,489,660,928 D 218,103,808 D 13,631,488 D 851,968 D 53,248 D 3,328 D 208 D 13 E 3,758,096,384 E 234,881,024 E 14,680,064 E 917,504 E 57,344 E 3,584 E 224 E 14 F 4,026,531,840 F 251,658,240 F 15,728,640 F 983,040 F 61,440 F 3,840 F 240 F 15 8 7 6 5 4 3 2 1
21 Chapter 1: Exercises 1. Convert the following binary integers to decimal: a. 11101 b. 101011 c. 111101 d. 1101101 e. 11101100 f. 10111101 g. 11011011010 h. 100001001010 2. Convert the binary integers in Exercise 1 to hexadecimal. 3. Convert the following hexadecimal integers to decimal: a. 302 b. 5CF c. F40 d. 1101 e. 24B6 f. 3AD2 g. 5E04E h. C20EE 4. Convert the hexadecimal integers in Exercise 3 to binary. 5. Convert the following decimal integers to binary. a. 13 b. 24 c. 85 d. 105 e. 256 f. 314 g. 1514 h. 12452 6. Convert the decimal integers in Exercise 5 to hexadecimal. 7. Each octal digit corresponds to a 3-bit integer as follows: 0 = 000 1 = 001 2 = 010 3 = 011 4 = 100 5 = 101 6 = 110 7 = 111 A) Convert to octal the following binary integers: a. 1001011 b. 10100110 c. 11010101 B) Convert to binary the following octal integers: a. 25o b. 342o c. 701o 8. Perform the following operations on binary integers: a. 1101 + 10 b. 111010 + 110111 c. 1101110 + 1011010 d. 110101011 + 110100111 e. 110110110 + 110110101 f. 110101-100101 g. 10110-101 h. 110010-10111 i. 110001-11010 j. 1001110-110101 9. Perform the following operations os: a. 11011 x 1101 b. 110101 x 1110 c. 100101010 1101 d. 11000111 1010 10. Perform the following operations on hexadecimal integers: a. 8D5 + 41A b. A5B + 53C c. 9876 + 9876 d. DEC4 + DA5D e. E8C - A21 f. E8C - A2E g. 3A41-1B2C h. 58DC - 3CED
22 Chapter 1: Solutions of Exercises 1. a. 29 b. 43 c. 61 d. 109 e. 236 f. 189 g. 1754 h. 2122 2. a. 1Dh b. 2Bh c. 3Dh d. 6Dh e. ECh f. BDh g. 6DAh h. 84Ah 3. a. 770 b. 1487 c. 3904 d. 4353 e. 9398 f. 15058 g. 385,102 h. 794,862. 4. a. 11 0000 0010 b. 101 1100 1111 c. 1111 0100 0000 d. 1 0001 0000 0001 e. 10 0100 1011 0110 f. 11 1010 1101 0010 g. 101 1110 0000 0100 1110 h. 1100 0010 0000 1110 1110. 5. a. 1101 b. 1 1000 c. 101 0101 d. 110 1001 e. 1 0000 0000 f. 1 0011 1010 g. 101 1110 1010 h. 11 0000 1010 0100. 6. a. Dh b. 18h c. 55h d. 69h e. 100h f. 13Ah g. 5EAh h. 30A4h. 7. a. 113o b. 246o c. 325o d. 10101 e. 11100010 f. 111000001 8. a. 1111 b. 1110001 c. 11001000 d. 1101010010 e. 1101101011 f. 10000 g. 10001 h. 11011 i. 10111 j. 11001. 9 a. 101011111 b. 1011100110 c. Quotient = 10110; Remainder = 1100 d. Quotient = 10011; Remainder = 1001 10. a. CEFh b. F97h c. 130ECh d. 1B921h e. 46Bh f. 45Eh g. 1F15h h. 1BEFh.