104 Midterm - Solutions
104 Midterm - Solutions
104 Midterm - Solutions
1. Convert the following number according to the corresponding describe, showing your work:
a. The decimal number (38) 10 to Roman number. (3%)
XXXVIII
b. The binary number (011110.01) 2 to hexadecimal pattern. (3%)
(1E.4) 16
c. The sign-and-magnitude binary number (11001110) 2 to decimal. (3%)
(–78) 10
d. The Internet address 17.234.34.14 to the 32-bit representation. (3%)
00010001 11101010 00100010 00001110
e. The real number (–0.375) 10 in 32-bit IEEE format. (3%)
–0.375 = -0.011 = –2–2 * 1.1
S = 1, E = -2 + 127 = 125 = (01111101)2
M = 10000000000000000000000 (22 zero at the right)
The result is 1 01111101 10000000000000000000000
2. Show the result of the following operations according to the corresponding describe, showing
your work.
a. Do the logic operation [(AE) 16 AND (3F) 16 ] OR [(32) 16 AND (DC) 16 ], and show the result in
binary. (4%)
(AE) 16 = (10101110) 2 , (3F) 16 = (00111111) 2 , (32) 16 = (00110010) 2 , (DC) 16 = (11011100) 2
(10101110) 2 AND (00111111) 2 = (00101110) 2
(00110010) 2 AND (11011100) 2 = (00010000) 2
(00101110) 2 OR (00010000) 2 = (00111110) 2
b. Assuming the numbers are stored in 16-bit two’s complement representation. Do the
operation (E12A) 16 + (9E27) 16 , and show the result in hexadecimal. (5%)
(E12A) 16 = (1110 0001 0010 1010) 2 and (9E27) 16 = (1001 1110 0010 0111) 2
1 1 1 1 1 Carry
1 1 1 0 0 0 0 1 0 0 1 0 1 0 1 0
+ 1 0 0 1 1 1 1 0 0 0 0 1 0 1 1 1
0 1 1 1 1 1 1 1 0 1 0 1 0 0 0 1
The result is not valid because of overflow.
c. Assuming the number are stored in 8-bit two’s complement representation. Do the operation
(–19) 10 – (23) 10 , and show the result in decimal. (5%)
(–19) 10 – (23) 10 = (–00010011) 2 – (00010111) 2 = (–00010011) 2 + (–00010111) 2 =
(11101101) 2 + (11101001) 2 = (–42) 10
d. Assuming the numbers are stored in 8-bit sign-and-magnitude representation, do the
operation (32) 10 – (73) 10 , and show the result in decimal. (5%)
32 = 00100000 and 73 = 01001001
1/2
Operation is subtraction, sign of (73) 10 is changed. S = 0 XOR 1 = 1.
The two’s complement of (73) 10 is (10110111) 2 .
There is no overflow … so (10101001) 2 = (–41) 10
AS 0 0 1 0 0 0 0 0
BS 1 + 0 1 1 0 1 1 1
1 0 1 0 1 1 1
RS 1 0 1 0 1 0 0 1
e. The floating-point operation (–12.625) 10 + (451.00) 10 in 32-bit IEEE format, and show the
result in decimal. (6%)
(–12.625) 10 + (451.00) 10 = – (1100.101) 2 + (111000011) 2
= –23 * (1.100101) 2 + 28 * (1.11000011) 2
A 1 10000010 10010100000000000000000
B 0 10000111 11000011000000000000000
We denormalize the numbers by adding the hidden 1’s to the mantissa and incrementing the
exponent. Now both denormalized mantissas are 24 bits and include the hidden 1’s.
A 1 10000011 110010100000000000000000
B 0 10001000 111000011000000000000000
We align the mantissas. We increment the first exponent by 5 and shift its mantissa to the
right five times.
A 1 10001000 000001100101000000000000
B 0 10001000 111000011000000000000000
Now we do sign-and-magnitude addition treating the sign and the mantissa of each number as
one integer stored in sign-and-magnitude representation.
R 0 10001000 1101101100110000000000
R 0 10000111 10110110011000000000000
E = (10000111) 2 = 135, M = 10110110011
(1.10110110011)2 × 2135−127 = (110110110.011) 2 = 438.375
3. We know that the operation of one’s complement simply reverses (flips) each bit, and the each
number must be 0 and 1 (not over two). The two’s complement of number is to first take the
one’s complement and then add 1 to the result. So assuming three-digit allocation, find the
sixteen’s complement of the following hexadecimal numbers. (6%)
a. –1E2 (E1E) 16
b. +FE1 (+FE1)16 → Overflow occurs because it is not in the range (−800)16 to (7FF)16
4. In a positional number system with base b, the largest integer number that can be represented
using k digits is bk – 1. Find the largest number in hexadecimal systems with four digits. And find
the minimum number of digits needed in the octal system for the seven-digit decimal number.
(6%)
(1) 164 −1 = 65535
(2) 8
2/2
5. Why is normalization necessary in the floating-point representation of real numbers? And what is
the mantissa? (4%)
(1) Normalization is necessary to make calculations easier.
(2) Mantissa is the bit sequence to the right of the decimal point after normalization.
6. In some countries vehicle license plates have two decimal digits (0 to 9). How many distinct
plates can we have? If the digit 0 is not allowed on the license plate, how many distinct plates
can we have? (4%)
(1) 102 = 100 if zero is allowed.
(2) 92 = 81 if zero is not allowed.
7. An imaginary computer has sixteen data register (R0 to R15), 1024 words in memory and 32
different instructions (add, subtract, and so on). What is the minimum size of an instruction in
bits if a typical instruction uses the following format: instruction M R2? (5%)
We need 4 bits to determine the instruction (24 = 16). We need 10 bits to address a word in
memory (210 = 1024). We need 4 bits to address a register (25 = 32). The size of the instruction is
therefore (4 + 10 + 5) or 19 bits.
Since the size of the instruction is 19 bits, we must have 19-bit data registers.
8. A computer uses memory-mapped I/O addressing. The address bus uses 10 lines (10 bits). If
memory made up of 1,000 words, how many three-register controllers can be accessed by the
computer. (4%)
The address bus uses 10 lines which mean that it can address 210 = 1024 words. Since the
memory is made of 1000 words and the system uses shared. (memory-mapped I/O) addressing,
1024−1000 = 24 words are available for I/O controllers. If each controller has 3 registers, then
24/3 = 8 controllers can be accessed in this system.
9. Using the instruction set of the simple computer in following table, write the code a program that
performs the following calculation: D ← A + B + C, in which A, B, C and D are integers in two’s
complement format. The user types the value of A, B, and C, and the value of D is displayed on
the monitor. The keyboard is assumed to be memory location (FE) 16 , and the monitor is assumed
to be (FF) 16. (6%)
3/2
10. Match the following to one or more layers of the TCP/IP protocol suite. (4%)
a. Creating user datagrams Transport layer
b. Deciding the routing of the packet Network layer
c. Providing services for the end user Application layer
d. Responsibility for handling frames between adjacent codes Data link layer
11. Define the protocol and describe why we need a protocol at each layer in the Internet. (3%)
A protocol defines the rules that both the sender and receiver and all intermediate devices need
to follow to be able to communicate effectively.
12. Why do we use the port numbers for communication in transport-layer? (3%)
The client program defines itself with a port number, called the ephemeral port Number. The
word ephemeral means short-lived and is used because the life of a client is normally short.
4/2
13. What is the difference between UDP and TCP in transport-layer protocols? (4%)
UDP is a connectionless, unreliable transport protocol and use a minimum of overhead.
TCP is a connection-oriented, reliable protocol. TCP explicitly defines connection establishment,
data transfer, and connection teardown phase to provide a connection-oriented service.
14. What the function of DNS? What is the drawback of a central directory system for the huge
Internet and how to solve this problem? (6%)
To identify an entity, TCP/IP protocols use the IP address, which uniquely identifies the
connection of a host to the Internet. However, people prefer to use names instead of numeric
address. Therefore, the Internet needs to have a dictionary system that cans a name to an address.
Since the Internet is so huge today, a central directory system cannot hold all the mapping.
In addition, if the central computer fails, the whole communication network will collapse.
Distribute the information among the many computers in the world.
The host that needs mapping can contact the closest computer holding the needed information.
15. During the weekend, Alice often needs to access files stored on her office desktop, from her
home laptop. Last week, she installed a copy of the FTP server process on her desktop at her
office and a copy of the FTP client process on her laptop at home. She was disappointed when
she could not access her files during the weekend. What could have gone wrong? Assume the
files are still integrity on her office desktop and the status of FTP system is fine. (5%)
Probably Alice turned off her desktop, which stopped the FTP server, when she left the office. A
server process should be running all the time, waiting for clients to access it.
2/2