Sheet 1 Solution.pdf
Document Details
Uploaded by UnlimitedTroll
Tags
Full Transcript
Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed ...
Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 2. Main Memory 1. If the memory cell whose address is 5 contains the value 8, what is the difference between writing the value 5 into cell number 6 and moving the contents of cell number 5 into cell number 6? The differences between the two are: I. Writing 5 into cell 6 is single write operation whereas writing contents of cell 5 into cell 6 will be two operation (first, read operation to get the contents of cell 5 and second, write operation to write the value in cell 6) II. When 5 is written, final value of cell 6 will be 5 whereas when contents of cell 5 are written, final value of cell 6 will be 8. Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 2. Main Memory 2. Suppose you want to interchange the values stored in memory cells 2 and What is wrong with the following sequence of steps: Step 1. Move the contents of cell number 2 to cell number 3. Step 2. Move the contents of cell number 3 to cell number 2. Design a sequence of steps that correctly interchanges the contents of these cells. If needed, you may use additional cells. The sequence is wrong because as soon as Step1 is executed, contents of cell number 3 are over-written and original contents are lost. Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed The correct Steps are: 1. Move contents of cell number 3 to a temporary cell (Call it cell number 4) 2. Move contents of cell number 2 to cell number 3 3. Move contents of cell number 4 to cell number 2 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 2. Main Memory 3. How many bits would be in the memory of a computer with 4KB memory? Every Byte is 8 bits A KB is 210 bytes i.e., 1024 bytes So 4 KB = 4 * 1024 * 8 bits = 32768 bits Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 3. Mass Storage 1. What is gained by increasing the rotation speed of a disk or CD? Increasing the rotation speed of a disk or CD provides several benefits, including faster data transfer, reduced access time, higher data transfer rate, improved seek time, and enhanced performance for optical media. However, there are limits to how fast a disk can rotate due to physical constraints and technological limitations. Excessive rotation speeds can lead to operational issues and reduced lifespan of the disk drive. Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 3. Mass Storage 2. When recording data on a multiple-disk storage system, should we fill a complete disk surface before starting on another surface, or should we first fill an entire cylinder before starting on another cylinder? It is more efficient to fill an entire cylinder before starting on another cylinder. This minimizes the movement of the read/write heads, reducing seek time and improving data recording and retrieval speed. Sequentially accessing data within a cylinder is faster than moving between different disk surfaces. Thus, filling a complete disk surface before starting on another surface would result in increased seek time and potentially degrade performance. Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 3. Mass Storage 3. Why should the data in a reservation system that is constantly being updated be stored on a magnetic disk instead of a CD or DVD? A reservation system that undergoes constant updates is better suited for storage on a magnetic disk rather than a CD or DVD. Magnetic disks, such as hard disk drives (HDDs), offer read/write capabilities and faster data transfer rates, allowing for efficient and frequent updates. They provide larger storage capacity, flexibility, and scalability compared to CDs or DVDs. Additionally, magnetic disks are more durable and reliable, making them suitable for the demanding nature of a constantly updated reservation system. Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 3. Mass Storage 4. What factors allow CD, DVD, and Blu-ray disks all to be read by the same drive? CD, DVD, and Blu-ray disks can be read by the same drive due to factors such as backward compatibility, a shared optical pickup mechanism, differences in reflectivity, and the drive's ability to interpret different data encoding and structure techniques. These factors enable the drive to read and retrieve data from CDs, DVDs, and Blu-ray disks, providing compatibility and convenience for users with different types of optical media. Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 3. Mass Storage 5. What advantage do flash drives have over the other mass storage systems introduced in this section? Flash drives have several advantages over other mass storage systems. They are highly portable, durable, and compact, allowing users to carry their data easily. Flash drives offer faster access times, thanks to their lack of mechanical parts. They use solid-state technology, consuming less power and generating less heat. Flash drives are compatible with various devices and offer easy data transfer. They also provide high storage capacities, making them a popular choice for mass storage needs. Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 3. Mass Storage 5. What advantage do flash drives have over the other mass storage systems introduced in this section? Cont.: In magnetic or optical technology, physical motion, such as spinning disks, moving read/write heads, and aiming laser beams, is required to store and retrieve data. This means that data storage and retrieval is slow compared to the speed of electronic circuitry. Flash memory technology has the potential of alleviating this drawback. In a flash memory system, bits are stored by sending electronic signals directly to the storage medium where they cause electrons to be trapped in tiny chambers of silicon dioxide, thus altering the characteristics of small electronic circuits. Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 3. Mass Storage 6. What advantages continue to make magnetic hard disk drives competitive? Compared to flash drives, magnetic HDDs offer a much lower cost per bit, meaning that, for the same price, HDDs will provide more space. This is particularly important in data centers and servers which often rely on thousands of individual HDDs for hosting media, storing backups, and providing data to cloud-based applications. HDDs also have a virtually unlimited number of read/write cycles, whereas modern SSDs are lucky to get 1 million cycles. This means that HDDs are suitable for long- term data storage and can be reused many times while showing no degradation in performance. Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 4. Representing information as bit patterns 01000011 2 → 67 10 → C 01100101 2 → 101 10 → e 01101111 2 → 111 10 → o 01110010 2 → 114 10 → r 01101101 2 → 109 10 → m 00100000 2 → 32 10 → ‘ ’ (space) 01110000 2 → 112 10 → p 01110101 2 → 117 10 → u 01110100 2 → 116 10 → t Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 4. Representing information as bit patterns 01010011 2 → 83 10 → S 01100101 2 → 101 10 → e 01100011 2 → 99 10 → c 01101001 The message is: 2 → 105 10 → i Computer Science 01100101 2 → 101 10 → e 01101110 2 → 110 10 → n 01100011 2 → 99 10 → c Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 4. Representing information as bit patterns 2. In the ASCII code, what is the relationship between the codes for an uppercase letter and the same letter in lowercase? The difference between the ASCII value of an uppercase character and the ASCII value of the same character but in lowercase is 32 i.e. the sixth bit is set (1) in lowercase and cleared (0) in uppercase Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 4. Representing information as bit patterns 3. Encode these sentences in ASCII: a. “Stop!” Cheryl shouted. b. Does 2 + 3 = 5? a. 00100010 01010011 01110100 1101111 01110000 0100001 0100010 0100000 01000011 01101000 01100101 01110010 01111001 01101100 00100000 01110011 01101000 01101111 01110101 01110100 01100101 01100100 00101110 b. 01000100 01101111 01100101 01110011 00100000 00110010 00100000 00101011 00100000 00110011 00100000 00111101 00100000 00110101 00111111 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 4. Representing information as bit patterns 4. Describe a device from everyday life that can be in either of two states, such as a flag on a flagpole that is either up or down. Assign the symbol 1 to one of the states and 0 to the other, and show how the ASCII representation for the letter b would appear when stored with such bits. 'b' is represented in ASCII as 98 10. The equivalent binary is 01100010 2. An electric bulb is a device that can be described using two states. It is either ON or OFF. ON state can be represented using 1 and OFF state can be represented using 0. Hence, ASCII 'b' will be, OFF ON ON OFF OFF OFF ON OFF Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 4. Representing information as bit patterns 5. Convert each of the following binary representations to its equivalent base 10 form: a. 0101 b. 1001 c. 1011 d. 0110 e. 10000 f. 10010 a. 0101 → 1 ∗ 20 + 0 ∗ 21 + 1 ∗ 22 + 0 ∗ 23 = 5 b. 1001 → 1 ∗ 20 + 0 ∗ 21 + 0 ∗ 22 + 1 ∗ 23 = 9 c. 1011 → 1 ∗ 20 + 1 ∗ 21 + 0 ∗ 22 + 1 ∗ 23 = 11 d. 0110 → 0 ∗ 20 + 1 ∗ 21 + 1 ∗ 22 + 0 ∗ 23 = 6 e. 10000 → 0 ∗ 20 + 0 ∗ 21 + 0 ∗ 22 + 0 ∗ 23 + 1 ∗ 24 = 16 f. 10010 → 0 ∗ 20 + 1 ∗ 21 + 0 ∗ 22 + 0 ∗ 23 + 1 ∗ 24 = 18 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 4. Representing information as bit patterns 6. Convert each of the following base 10 representations to its equivalent binary form: a. 6 b. 13 c. 11 d. 18 e. 27 f. 4 a. 6 → 0 ∗ 20 + 1 ∗ 21 + 1 ∗ 22 + 0 ∗ 23 = 0110 b. 13 → 1 ∗ 20 + 0 ∗ 21 + 1 ∗ 22 + 1 ∗ 23 = 1101 c. 11 → 1 ∗ 20 + 1 ∗ 21 + 0 ∗ 22 + 1 ∗ 23 = 1011 d. 18 → 0 ∗ 20 + 1 ∗ 21 + 0 ∗ 22 + 0 ∗ 23 + 1 ∗ 24 = 10010 e. 27 → 1 ∗ 20 + 1 ∗ 21 + 0 ∗ 22 + 1 ∗ 23 + 1 ∗ 24 = 11011 f. 4 → 0 ∗ 20 + 0 ∗ 21 + 1 ∗ 22 + 0 ∗ 23 = 0100 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 4. Representing information as bit patterns 7. What is the largest numeric value that could be represented with three bytes if each digit were encoded using one ASCII pattern per byte? What if binary notation were used? 3 bytes = 3*8 bits = 24 bits 999 is the largest numeric value that could be represented with three bytes if each digit were encoded using one ASCII pattern per byte. 999 10 = 1111100111 2 Here only 10 bits are used to represent 999 number. Using 3 bytes, we can store any signed integer in the range from 0 to 224−1 − 1 in these 24 bits. Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 4. Representing information as bit patterns 7. What is the largest numeric value that could be represented with three bytes if each digit were encoded using one ASCII pattern per byte? What if binary notation were used? Cont. 24 bits, each of them can hold either 0 or 1, using simple counting principles, there are 224−1 different combinations of integers (because a bit is reserved for sign convention) and the representation of zero is included in the positive numbers but there is NO "negative zero". Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 4. Representing information as bit patterns 8. An alternative to hexadecimal notation for representing bit patterns is dotted decimal notation in which each byte in the pattern is represented by its base 10 equivalent. In turn, these byte representations are separated by periods. For example, 12.5 represents the pattern 0000110000000101 (the byte 00001100 is represented by 12, and 00000101 is represented by 5), Represent each of the following bit patterns in dotted decimal notation. a. 0000111100001111 b. 001100110000000010000000 c. 0000101010100000 a. 00001111 00001111 → 15.15 b. 00110011 00000000 10000000 → 51.0.128 c. 00001010 10100000 → 10.160 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 4. Representing information as bit patterns 9. What is an advantage of representing images via geometric structures as opposed to bit maps? What about bit map techniques as opposed to geometric structures? Geometric representations are more conductive to changes in scale than images encoded as bitmaps. However, geometric representations do not typically provide the same photographic quality that bitmaps produce. Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 5. The Binary System 1. Convert each of the following binary representation to its equivalent base 10 from: a.101010 b.100001 c.10111 d.0110 e.11111 a. 101010 → 0 ∗ 20 + 1 ∗ 21 + 0 ∗ 22 + 1 ∗ 23 + 0 ∗ 24 + 1 ∗ 25 = 42 b. 100001 → 1 ∗ 20 + 0 ∗ 21 + 0 ∗ 22 + 0 ∗ 23 + 0 ∗ 24 + 1 ∗ 25 = 33 c. 10111 → 1 ∗ 20 + 1 ∗ 21 + 1 ∗ 22 + 0 ∗ 23 + 1 ∗ 24 = 23 d. 0110 → 0 ∗ 20 + 1 ∗ 21 + 1 ∗ 22 + 0 ∗ 23 = 6 e. 11111 → 1 ∗ 20 + 1 ∗ 21 + 1 ∗ 22 + 1 ∗ 23 + 1 ∗ 24 = 31 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 5. The Binary System 2. Convert each of the following base 10 representation to its equivalent binary from: a.32 b.64 c.96 d.15 e.27 a.32 b.64 c.96 d.15 e.27 32/2=16 → R=0 64/2=32 → R=0 96/2=48 → R=0 15/2=7 → R=1 27/2=13 → R=1 16/2=8 →R=0 32/2=16 → R=0 48/2=24 →R=0 7/2=3 →R=1 13/2=6 →R=1 8/2=4 →R=0 16/2=8 →R=0 24/2=12 →R=0 3/2=1 →R=1 6/2=3 →R=0 4/2=2 →R=0 8/2=4 →R=0 12/2=6 →R=0 1/2=0 →R=1 3/2=1 →R=1 2/2=1 →R=0 4/2=2 →R=0 6/2=3 →R=0 ANS:1111 1/2=0 →R=1 1 /2=0 → R=1 2/2=1 →R=0 3/2=1 → R=1 ANS:11011 ANS:100000 1 /2=0 → R=1 1/2=0 → R=1 ANS:1000000 ANS:1100000 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 5. The Binary System 3. Convert each of the following binary representation to its equivalent base 10 from: a.11.01 b.101.111 c.10.1 d.110.011 e.0.101 a. 11.01 → 1 ∗ 21 + 1 ∗ 20 + 0 ∗ 2−1 + 1 ∗ 2−2 = 3.25 b. 101.111→ 1 ∗ 22 + 0 ∗ 21 + 0 ∗ 20 + 1 ∗ 2−1 + 1 ∗ 2−2 + 1 ∗ 2−3 = 5.875 c. 10.1 → 1 ∗ 21 + 0 ∗ 20 + 1 ∗ 2−1 = 2.5 d. 110.011 → 1 ∗ 22 + 1 ∗ 21 + 0 ∗ 20 + 0 ∗ 2−1 + 1 ∗ 2−2 + 1 ∗ 2−3 = 6.375 e. 0.101 → 0 ∗ 20 + 1 ∗ 2−1 + 0 ∗ 2−2 + 1 ∗ 2−3 = 0.625 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 5. The Binary System 4. Express the following floating point decimal values in binary notation: a.4.5 b.2.75 c.1.125 d.0.3125 e.5.625 a. 4.5 b. 2.75 c. 1.125 d. 0.3125 e. 5.625 4 → 4/2=2 → R=0 2 → 2/2=1 → R=0 1→1/2=0 → R=1 0 →0/2=0 → R=0 5→5/2=2 → R=1 2/2=1 → R=0 2/2=1 → R=0 1/2=0 → R=1 0.125 →0.125∗2=0.25 0.3125 →0.3125 ∗ 2=0.625 1/2=0 → R=1 1/2=0 → R=1 0.75 →0.75 ∗ 2=1.5 0.25 ∗2=0.5 0.625 ∗ 2=1.25 0.25 ∗ 2=0.5 0.625 →0.625 ∗ 2=1.25 0.5 → 0.5 ∗ 2=1 0.5 ∗ 2=1 0.5 ∗2=1 0.5 ∗ 2 =1 0.25 ∗2=0.5 0.5 ∗2=1 ANS:100.1 ANS:10.11 ANS:0.0101 ANS:101.101 ANS:1.001 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 5. The Binary System 5. Perform the following additions in binary notation: a. 11011 b. 1010.001 c. 11111 d. 111.11 + + + + 01100 0001.101 00001 000.01 100111 1011.110 100000 1000.00 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 6. Storing Integers 1. Convert each of the following two’s complement representations to its equivalent base 10 form: a.00011 b. 01111 c.11100 d.11010 e.00000 f.10000 If MSB = 0, i.e., the number is +ve, perform normal conversion. Otherwise, if MSB = 1, do the following: Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 6. Storing Integers 1. Convert each of the following two’s complement representations to its equivalent base 10 form: a.00011 b. 01111 c.11100 d.11010 e.00000 f.10000 a. 00011→ 1 ∗ 20 + 1 ∗ 21 + 0 ∗ 22 + 0 ∗ 23 + 0 ∗ 24 = 3 b. 01111→ 1 ∗ 20 + 1 ∗ 21 + 1 ∗ 22 + 1 ∗ 23 + 0 ∗ 24 = 15 c. 11100→ (get 1’s complement) 00011 + 1=00100 → 0∗ 20 + 0 ∗ 21 + 1 ∗ 22 + 0 ∗ 23 + 0 ∗ 24 = −4 d. 11010→(get 1’s complement) 00101 + 1 = 00110→0 ∗ 20 + 1 ∗ 21 + 1 ∗ 22 + 0 ∗ 23 + 0 ∗ 24 = −6 e. 00000→ 0 ∗ 20 + 0 ∗ 21 +0 ∗ 22 + 0 ∗ 23 + 0 ∗ 24 = 0 f. 10000→(get 1’s complement) 01111 + 1 = 10000→0 ∗ 20 + 0 ∗ 21 + 0 ∗ 22 + 0 ∗ 23 + 1 ∗ 24 = −16 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 6. Storing Integers 2. Convert each of the following base 10 representations to its equivalent two’s complement form using patterns of 8 bites: a.6 b. -6 c.-17 d.13 e.-1 f.0 a. 6 b. - 6 c. - 17 d. 13 e. - 1 6/2=3 → R=0 6/2=3 → R=0 17/2=8 → R=1 13/2=6 → R=1 1/2=0 → R=1 3/2=1 → R=1 3/2=1 → R=1 8/2=4 → R=0 6/2=3 → R=0 1/2=0 → R=1 1/2=0 → R=1 4/2=2 → R=0 3/2=1 → R=1 We get: 00000001 Ans:00000110 We get: 00000110 2/2=1 → R=0 1/2=0 → R=1 (1’s complement): (1’s complement): 1/2=0 → R=1 11111110 11111001 We get: 00010001 Ans = 00001101 + + (1’s complement): 00000001 00000001 11101110 Ans = 11111111 Ans =11111010 + 00000001 Ans =11101111 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 6. Storing Integers 2. Convert each of the following base 10 representations to its equivalent two’s complement form using patterns of 8 bites: a.6 b. -6 c.-17 d.13 e.-1 f.0 f. 0 0/2=0 → R=0 Ans = 00000000 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 6. Storing Integers 3. Suppose the following bit patterns represent values stored in two’s complement notation find the two’s complement representation of the negative of each value : a.00000001 b. 01010101 c.11111100 d.11111110 e.00000000 f. 01111111 a.00000001 b.01010101 c.11111100 (1’s complement): (1’s complement): (1’s complement): 11111110 10101010 00000011 + + + 00000001 00000001 00000001 Ans =11111111 Ans =10101011 Ans = 00000100 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 6. Storing Integers 3. Suppose the following bit patterns represent values stored in two’s complement notation find the two’s complement representation of the negative of each value : a.00000001 b. 01010101 c.11111100 d.11111110 e.00000000 f. 01111111 d.11111110 e.00000000 f.01111111 (1’somplement): (1’s complement): (1’s complement): 00000001 11111111 10000000 + + + 00000001 00000001 00000001 Ans =00000010 Ans = 00000000 Ans =10000001 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 6. Storing Integers 4. Suppose a machine numbers in two’s complement notation what are the largest and smallest numbers that can be stored if the machine uses bit patterns of the following : a. Four b. Six c. Eight From −𝟐𝒏−𝟏 to (2𝑛−1 −1) a. Four Smallest value : −𝟐𝟒−𝟏 = −8 Largest value : 𝟐𝟒−𝟏 − 𝟏 = 𝟖 − 𝟏 = 𝟕 b. Six Smallest value : −𝟐𝟔−𝟏 = −32 Largest value : 𝟐𝟔−𝟏 − 𝟏 = 𝟑𝟐 − 𝟏 = 𝟑𝟏 c. Eight Smallest value : −𝟐𝟖−𝟏 = −128 Largest value : 𝟐𝟖−𝟏 − 𝟏 = 𝟏𝟐𝟖 − 𝟏 = 𝟏𝟐𝟕 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 6. Storing Integers 5. In the following problem ,each bit pattern represents a value stored in two’s complement notation find the answer to each problem in two’s complement notation by performing the addition process described in the text. Then check your work by translating the problem and your answer into base 10 notation : a.0101+0010 b. 0011+0001 c.0101+1010 d.1110+0011 e.1010+1110 a.0101+0010 b.0011+0001 c.0101+1010 d.1110+0011 e.0101+1110 0101 →5 0011 →3 0101 →5 1110 →-1 0101 →5 +0010 →2 +0001 →1 +1010 →-6 +0011 →3 +1110 →-2 =0111 →7 =0100 →4 =1111 →-1 =0001 →1 =0011 →3 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 6. Storing Integers 6. watch overflow and indicate which answers are incorrect because of this phenomenon: Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 6. Storing Integers 6. watch overflow and indicate which answers are incorrect because of this phenomenon: Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 6. Storing Integers 6. Solve each of the following problems in two’s complement notation, but this watch overflow and indicate which answers are incorrect because of this phenomenon: a.0100+0011 b. 0101+0110 c.1010+1010 d.1010+0111 e.0111+0001 a.0100+0011 b.0101+0110 c.1010+1010 0100 0101 1010 +0011 +0110 +1010 =0111 (7) =1011 (overflow) =0100 (overflow) d.1010+0111 e.0111+0001 1010 0111 +0111 +0001 =0001 =1000 (overflow) Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 6. Storing Integers 7. Translate each of the following problems from base 10 notation into two’s complement notation using bit patterns of length four ,then convert each problem to an equivalent addition problem (as machine might do)and perform the addition. Check your answer by converting them back to base 10 notation : a.6 − (−1) b. 3 − (−2) c. 4 − 6 d. 2 − (−4) e. 1 − 5 a. 0110 b. 0011 c. 0100 d. 0010 e. 0001 + + + + + 0001 0010 1010 0100 1011 0111 (7) 0101 (5) 1110 (-2) 0110 (6) 1100 (-4) Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 6. Storing Integers 8. Can overflow ever occur when are added in two’s complement notation with one value positive and the other negative ?Explain your answer. No. Overflow occurs when an attempt is made to store a number that is too large for the system being used. When adding a positive value to a negative value, the result must be between the values being added. Therefore the result will be small enough to be stored without error. Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 6. Storing Integers 9. Convert each of the following excess eight representation to its equivalent base 10 from without referring to the table in the text: a.1110 b. 0111 c.1000 d.0010 e.0000 f.1001 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 6. Storing Integers 9. Convert each of the following excess eight representation to its equivalent base 10 from without referring to the table in the text: a.1110 b. 0111 c.1000 d.0010 e.0000 f.1001 a. 1110→ 1 ∗ 23 + 1 ∗ 22 + 1 ∗ 21 + 0 ∗ 20 = 14 − 8 = 6 b. 0111→ 0 ∗ 23 + 1 ∗ 22 + 1 ∗ 21 + 1 ∗ 20 = 7 − 8 = -1 c. 1000→ 1 ∗ 23 + 0 ∗ 22 + 0 ∗ 21 + 0 ∗ 20 = 8 − 8 = 0 d. 0010→ 0 ∗ 23 + 0 ∗ 22 + 1 ∗ 21 + 0 ∗ 20 = 2 − 8 = − 6 e. 0000→ 0 ∗ 23 + 0 ∗ 22 + 0 ∗ 21 + 0 ∗ 20 = 0 − 8 = − 8 f. 1001→ 1 ∗ 23 + 0 ∗ 22 + 0 ∗ 21 + 1 ∗ 20 = 9 − 8 = 1 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 6. Storing Integers 10. Convert each of the following base 10 representation to its equivalent excess eight from without referring to the table in the text: a.5 b. -5 c.3 d.0 e.7 f.-8 a. 5 + 8 = 13 → 1 ∗ 23 + 1 ∗ 22 + 0 ∗ 21 + 1 ∗ 20 = 1101 b. −5 + 8 = 3 → 0 ∗ 23 + 0 ∗ 22 + 1 ∗ 21 + 1 ∗ 20 = 0011 c. 3 + 8 = 11 → 1 ∗ 23 + 0 ∗ 22 + 1 ∗ 21 + 1 ∗ 20 = 1011 d. 0 + 8 = 8 → 1 ∗ 23 + 0 ∗ 22 + 0 ∗ 21 + 0 ∗ 20 = 1000 e. 7 + 8 = 15 → 1 ∗ 23 + 1 ∗ 22 + 1 ∗ 21 + 1 ∗ 20 = 1111 f. −8 + 8 = 0 → 0 ∗ 23 + 0 ∗ 22 + 0 ∗ 21 + 0 ∗ 20 = 0000 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 6. Storing Integers 11. Can the value 9 be represented in excess eight notation? What about representing 6 in excess four notation ? Explain your answer. No. The largest value that can be stored in excess eight notation is 7, represented by 1111. To represent a larger value, at least excess 16 (which uses patterns of 5 bits) must be used. Similarly, 6 cannot be represented in excess four notation. (The largest value that can be represented in excess four notation is 3) Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 7. Storing Fractions 1. Decode the following bit patterns using the floating-point format discussed in the text: a. 01001010 b. 01101101 c.00111001 d.11011100 e.10101011 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 7. Storing Fractions 1. Decode the following bit patterns using the floating-point format discussed in the text: a. 01001010 b. 01101101 c.00111001 d.11011100 e.10101011 1 bit 3 bits 4 bits +ve iff 0 exponent Mantissa -ve iff 1 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 7. Storing Fractions 1. Decode the following bit patterns using the floating-point format discussed in the text: a. 01001010 b. 01101101 c.00111001 d.11011100 e.10101011 Shift = exponent - 2𝑛−1 = exponent – 4 Answer is: Sign * Mantissa * 𝟐𝑺𝒉𝒊𝒇𝒕 a. 0 100 1010 First bit is 0 → It’s positive 100 → Shift = 4 – 4 = 0 1 1 5 1010 → 1 ∗ 2−1 + 0 ∗ 2−2 + 1 ∗ 2−3 + 0 ∗ 20 = + = 2 8 8 5 4−4 5 +1 ∗ ∗ 2 = 8 8 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 7. Storing Fractions 1. Decode the following bit patterns using the floating-point format discussed in the text: a. 01001010 b. 01101101 c.00111001 d.11011100 e.10101011 b. 0 110 1101 First bit is 0 → It’s positive 110 → Shift = 6 – 4 = 2 −1 −2 −3 −4 1 1 1 13 1101 → 1 ∗ 2 + 1 ∗ 2 + 0 ∗ 2 + 1 ∗ 2 = + + = 2 4 16 16 13 6−4 13 1 +1 ∗ ∗2 = =3 16 4 4 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 7. Storing Fractions 1. Decode the following bit patterns using the floating-point format discussed in the text: a. 01001010 b. 01101101 c.00111001 d.11011100 e.10101011 c. 0 011 1001 First bit is 0 → It’s positive 011 → Shift = 3 – 4 = -1 −1 −2 −3 −4 1 1 9 1001 → 1 ∗ 2 + 0 ∗ 2 + 0 ∗ 2 + 1 ∗ 2 = + = 2 16 16 9 3−4 9 +1 ∗ ∗2 = 16 32 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 7. Storing Fractions 1. Decode the following bit patterns using the floating-point format discussed in the text: a. 01001010 b. 01101101 c.00111001 d.11011100 e.10101011 d. 1 101 1100 First bit is 1 → It’s negative 101 → Shift = 5 – 4 = 1 −1 −2 −3 −4 1 1 3 1100 → 1 ∗ 2 + 1 ∗ 2 + 0 ∗ 2 + 0 ∗ 2 = + = 2 4 4 3 5−4 −1 ∗ ∗ 2 = −1.5 4 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 7. Storing Fractions 1. Decode the following bit patterns using the floating-point format discussed in the text: a. 01001010 b. 01101101 c.00111001 d.11011100 e.10101011 e. 1 010 1011 First bit is 1 → It’s negative 010 → Shift = 2 – 4 = − 2 1 1 1 11 1011 → 1 ∗ +0∗ 2−1 2−2 +1∗ 2−3 +1∗ 2−4 = + + = 2 8 16 16 11 2−4 11 −1 ∗ ∗2 =− 16 64 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 7. Storing Fractions 2. Encode the following values into the floating-point format discussed in the text. Indicate the occurrence of truncation errors: a. 23/4 b. 51/4 c. 3/4 d. − 31/2 e. − 43/8 Exponent = Shift + 2𝑛−1 = Shift + 4 𝟑 a. 𝟐 𝟒 = 𝟐. 𝟕𝟓 = 𝟏𝟎. 𝟏𝟏 𝟐 → Shift =2 Exponent = 2 + 4 = 6 = 𝟏𝟏𝟎 𝟐 First bit is 0 → Because it’s positive 0 110 1011 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 7. Storing Fractions 2. Encode the following values into the floating-point format discussed in the text. Indicate the occurrence of truncation errors: a. 23/4 b. 51/4 c. 3/4 d. − 31/2 e. − 43/8 𝟏 b. 5𝟒 = 𝟓. 𝟐𝟓 = 𝟏𝟎𝟏. 𝟎𝟏 𝟐 → Shift =3 Exponent = 3 + 4 = 7 = 𝟏𝟏𝟏 𝟐 First bit is 0 → Because it’s positive 0 111 1010 (Truncation error) Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 7. Storing Fractions 2. Encode the following values into the floating-point format discussed in the text. Indicate the occurrence of truncation errors: a. 23/4 b. 51/4 c. 3/4 d. − 31/2 e. − 43/8 𝟑 c. 𝟒 = 𝟎. 𝟕𝟓 = 𝟎. 𝟏𝟏 𝟐 → Shift =0 Exponent = 0 + 4 = 4 = 𝟏𝟎𝟎 𝟐 First bit is 0 → Because it’s positive 0 100 1100 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 7. Storing Fractions 2. Encode the following values into the floating-point format discussed in the text. Indicate the occurrence of truncation errors: a. 23/4 b. 51/4 c. 3/4 d. − 31/2 e. − 43/8 𝟏 d. −𝟑 𝟐 = −𝟑. 𝟓 = 𝟏𝟏. 𝟏 𝟐 → Shift =2 Exponent = 2 + 4 = 6 = 𝟏𝟏𝟎 𝟐 First bit is 1 → Because it’s negative 1 110 1110 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 7. Storing Fractions 2. Encode the following values into the floating-point format discussed in the text. Indicate the occurrence of truncation errors: a. 23/4 b. 51/4 c. 3/4 d. − 31/2 e. − 43/8 𝟑 e. −𝟒 𝟖 = −𝟒. 𝟑𝟕𝟓 = 𝟏𝟎𝟎. 𝟎𝟏𝟏 𝟐 → Shift =3 0.375 * 2 = 0.75 Exponent = 3 + 4 = 7 = 𝟏𝟏𝟏 0.75 * 2 = 1.5 𝟐 0.5 * 2 = 1.0 First bit is 1 → Because it’s negative 1 111 1000 (Truncation error) Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 7. Storing Fractions 3. In terms of the floating-point format discussed in the text, which patterns 01001001 and 00111101 represents the larger value? Describe a simple procedure for determining which of tow patterns represent the larger value. 01001001 (9/16) is larger than 00111101 (13/32). The following is a simple way of determining which of two patterns represent the larger value: Case 1. If the sign bits are different, the larger is the one with the 0 sign bit. (the positive) 01101010 10101110 The first one is larger because it’s positive and the other one is negative! Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 7. Storing Fractions 3. In terms of the floating-point format discussed in the text, which patterns 01001001 and 00111101 represents the larger value? Describe a simple procedure for determining which of tow patterns represent the larger value. 01001001 (9/16) is larger than 00111101 (13/32). The following is a simple way of determining which of two patterns represent the larger value: Case 2. If the sign bits are both 0, scan the remaining portions of the patterns from left to right until a bit mismatch. The pattern containing the 1 in this position represents the larger value. 01010110 01011100 The second one is larger because at first mismatching position it contains a 1 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 7. Storing Fractions 3. In terms of the floating-point format discussed in the text, which patterns 01001001 and 00111101 represents the larger value? Describe a simple procedure for determining which of tow patterns represent the larger value. 01001001 (9/16) is larger than 00111101 (13/32). The following is a simple way of determining which of two patterns represent the larger value: Case 3. If the sign bits are both 1, scan the remaining portions of the patterns from left to right until a bit mismatch. The pattern containing the 0 in this position represents the larger value. 11010110 11011100 The first one is larger because at first mismatching position it contains a 0 Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed 7. Storing Fractions 4. When using the floating-point format discussed in the text, what is the largest value can be represented? What is the smallest positive value that can be represented? The Largest value would be 71/2 which is represented by the pattern 01111111. As for the smallest positive value, you could argue that there are two correct answers. First, if you stick to the coding process described in the text, which requires the most significant bit of the mantissa to be 1 ( called normalized form ), the answer is 1/32, represented by the pattern 00001000. However, most machines do NOT impose this restriction for values close to 0. for such a machine, the correct answer is 1/256 represented by 00000001. Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed Programming Team Mohamed Amr, Ahmed Yassin, Mariam Osama, Fatma Mohamed