CEG2136 Practice Questions and Solutions for Test 2 PDF

Title CEG2136 Practice Questions and Solutions for Test 2
Author Aleana Wright
Course Computer Architecture I
Institution University of Ottawa
Pages 8
File Size 427.1 KB
File Type PDF
Total Downloads 8
Total Views 133

Summary

Practice questions and solutions for second year computer architecture...


Description

COURSE: SEMESTER:

CEG2136 Computer Architecture I Fall 2021

Practice Problems 2 Data Representation Q1. In a signed binary system of 8 bits (N=8): a) Find the 2’s complement representation of the following signed numbers: (+ 63)10 and (- 115)10. b) Find the 2’s complement of the following signed numbers and give your results in decimal, too: (- 63)10 and (+ 115)10 c) Perform the following arithmetic operations using the signed 2’s complement representation and provide your results in decimal (including intermediary steps), as well: 1) (+ 115)10 + (- 63)10 2) (- 115)10 - (- 63)10 Q2. a) Identify the decimal number which is represented next with 32-bit in the IEEE 754 standard: (1 10001011 11101000000000000000000) = (?)10 b) Represent (221.390625) in the IEEE 754 standard with 32 bits. Questions 3.1, 3.3 – 3.5, 3.8, 3.10, 3.13, 3.16

Solutions Q1. In a signed binary system with 8 bits (N=8): a) Find the 2’s complement representation of the following signed numbers: (+63)10 = (00111111)2 ⸦ [-128,+127] 63/2 remainder lsb 31 1 15 1 7 1 3 1 1 1 0 1

20 21 22 23 24 25

+63=

Sign 0

26 0

25 1

24 1

Or observe that 63 = 32+16+8+4+2+1

23 1

22 1

21 1

20 1

(-115)10 = (10001101)2 ⸦ [-128,+127] 115/2 remainder 57 1 28 1 14 0 7 0 3 1 1 1 0 1

20 21 22 23 24 25 msb 26

lsb

+115=

Sign 0

26 1

25 1

24 1

23 0

22 0

21 1

20 1

-115 = 2’s complement of (01110011) = 10001101

b) Find the 2’s complement of the following signed numbers and give your results in decimal, too: (- 63)10 and (+ 115)10 The 2’s complement representation of (-63)10 = 2’s complement of (00111111)2 = (11000001)2 => Do the 2’s complement of (- 63)10 as required in the question: 2’s complement of (11000001)2 = (00111111)2 = which is the 2’s complement representation of (+63)10, which in fact is the result that was expected. The 2’s complement representation of (+115)10 = (01110011) => Do the 2’s complement of (+115)10 = 2’s complement of (01110011) = (10001101)2 = 2’s complement representation of (-115)10 c) Perform the following arithmetic operations using the signed 2’s complement representation and provide your results in decimal (including intermediary steps), as well: 1)

CY:

A+ B S=A+B

2)

CY:

C+ -D X=C-D

Say A = (+ 115)10 and B = (- 63)10 S = A + B = (+ 115)10 + (- 63)10 = +5210 ⸦ [-128,+127] 2’s complement representation Base 10 CY8 CY7 CY 6 CY5 CY4 CY 3 CY2 CY1 CY0 1 1 0 0 0 0 1 1 0

0 1 1 1 1 0 0 0 1

1 0 0 1 0 0 0 0 1 0 1 0

1 1 0

11510+ -6310 5210 Coincides with expected result, confirmed by CY8 = CY7 = 1 => NO overflow

Say C = (- 115)10 and D = (- 63)10 X = C - D = (- 115)10 - (- 63)10 = (- 115)10 + [- (- 63)]10 = (- 115)10 + (+63)10 2’s complement representation Base 10 CY8 CY7 CY 6 CY5 CY4 CY 3 CY2 CY1 CY0 0 0 1 1 1 1 1 1 0

1 0 0 0 1 1 0 0 0 1 1 1 1 1 1 1 0 0 1 1 0

1 1 0

-11510 6310 -5210

Coincides with expected result, confirmed by CY8 = CY7 = 0 => NO overflow Convert the binary result 110011002 to decimal to compare with the result of the decimal verification: As the msb of X = C-D is 1 => X is a negative number (X = –y) with a magnitude |X| =y =-(-y) = -(X) = 2’s complement of (X) = 2’s complement of (11001100) = 00110100 = 5210 => X = -y = -5210 Alternatively, X can be converted to decimal as follows: X = 110011002 = -27+26+23+22 = -128+64+8+4 = -52

Q2. a) Identify the decimal number which is represented next with 32-bit in the IEEE 754 standard: (1 10001011 11101000000000000000000) = (?)10 Sign = 1: => negative ; E = 128+8+3 = 139, hence exponent = E-127 = 12 1.M = 1.11101 (where M = mantissa) -1.11101 • 212= -1 1110 1000 0000=-(212+211+210+29+27) = -(4096+2048+1024+512+128) = (-7808)10 b) Represent (221.390625) in the IEEE 754 standard with 32 bits. (221.390625)10 = (11011101.011001)2 = (1.1011101011001) x 27 Sign = 0; Exp = 7; E = 127 + 7 = 134 = (10000110)2 M = 1011101011001 (221.390625)10 = (0 10000110 10111010110010000000000 ) in IEEE754 3.1. Convert the following binary numbers to decimal 101110; 1110101; and 110110100.

3.3. Convert the following decimal numbers to binary: 1231; 673, and 1998,

3.4 Convert the following decimal numbers to the bases indicated. a. 7562 to octal b. 1938 o hexadecimal c. 175 to binary 3.5. Convert the hexadecimal number F3A7C2 to binary and octal

3.8. Show the bit configuration of a 24-bit register when its content represents the decimal equivalent of 295: (a) in binary; (b) in BCD; (c) in ASCII using eight bits with even parity 29510 = 256 + 32 + 7 = 28+25+22+21+20 223

29

28

27

26

25

24

23

22

21

20

0 0 0 0 0 0 0

1

0

0

1

0

0

1

1

1

(b) BCD 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 (c) 29510 in ASCII using eight bits with even parity 1 0 1 1 0 0 1 0 0 0 1 1 1 0 0

0

1 0

0

1

0

1

0

1

1

0 0

1

1

0

(a)binary

216

0 0 0 0 0 0 0 0

215

1

0

1

3.10. Decode the following ASCII code: 1001010 1001111 1001000 4A 4F 48 J O H

1001110 4E N

0100000 20

1000100 44 D

3.13. Obtain the 1's and 2's complements of the following eight-bit numbers: 10101110; 10000001 10000000 00000001 1's compl 2’s compl

1001111 4F O

1000101 45 E

00000000.

3.16. Perform the arithmetic operations (+42) + (-13) and (-42) - (-13) in binary using signed-2's complement representation. +42 = -42 =

0 1 0 1 0 1 0 1 0 1 0 1 1 0 (+42) + (-13)

(+42) (-13) (+29)

+13 0 0 0 1 1 0 1 -13 1 1 1 0 0 1 1 (-42) - (-13) = (-42) + (+13)

0 1 0 1 0 1 0 1 1 1 0 0 1 1 0 0 1 1 1 0 1

(-42) 1 0 1 0 1 1 0 (+13) 0 0 0 1 1 0 1 (-29) 1 1 0 0 0 1 1

More practice questions 1.1 Fill out each row of the following table with the corresponding representation in other bases of the number given in that row; show the details of your calculations.

(a) (b)

decimal 25.5 10.25

binary 1 1001.1 1010.01

hexadecimal 19.8 A.4

octal 31.4 12.2

(c) 26 1 1010 1A 32 (d) 26 1 1010 1A 32 Answers are in bold and highlighted, as follows: (a) 25.510 = 16 + 8 + 1 + ½ = 1 1001.12 = 1 1001.1000=19.816 = 11 001.100=31.48 (b) 1010.012 = 8+2+1/4 = 10.2510 =1010.0100 = A.416 = 1 010.010 = 12.28 (c) 1A16 = 1 10102 = 16+10 = 2610 = 11 010 = 32 (d) Since the last 2 numbers in the last column is the same (32), it means that the last 2 rows represent the same value, such that their elements are identical.

1.2 In the 8-bit signed 2’s complement representation, the number of distinct numbers from [-128,127] is: (a) 256 (b) 128 (c) 255 (d) None of these 1.3 7-bit registers are used in this question to store numbers expressed in 2’s complement representation. (a) Convert the following two signed numbers to binary observing the above assumption: A = (- 31)10 sgn 25 24 23 22 A’s magnitude represented on 7 bits: |-31| = 31 = 16 + 8 + 4 + 2 + 1 = 0 0 1 1 1 => A = -31 = 2’s complement (001 1111) = 110 0001 B = (+ 63)10 = 011 1111

21

20

1 1

(b) Find the 2’s complement of the signed binary numbers A and B, and give your results in decimal, too: Doing the 2’s complement of a signed binary number will negate the number 2’s complement of A = 2’s complement (110 0001) = 001 1111 2’s complement of A in decimal: 001 11112 = +3110 2’s complement of B = 2’s complement (011 1111) = 100 0001, which is a negative number say -x. The value of a signed number in 2’s complement representation = (1)•26+1=- 63; or, to find the magnitude (x = |-x|) of this number (-x) we complement it, since x = -(-x) = 2’s complement (-x) = 2’s complement (100 0001) = 011 1111 = +63 => 2’s complement of B in decimal = - x = - 63, which makes sense, since complementing B = 63, we negate its value to -63. (c) Perform the following arithmetic operations in signed-2’s complement representation, using a 7- bit ALU; show operations and results (including intermediary steps), both in binary and in decimal. Are there any overflows? How can a computer detect overflow? (+ 63)10 + (- 31)10 Carry:

1

+63 - 31 +32

1

1

1

1

1

1

0 1 1 1 1 1 1 1 1 0 0 0 0 1 0 1 0 0 0 0 0

(- 63)10 - (- 31)10 Carry:

- 63 +31 -32

0

0

1

1

1

1

1

1 0 0 0 0 0 1 0 0 1 1 1 1 1 1 1 0 0 0 0 0

Converted to decimal: +32

The result 110 0000 is a negative number -26 +25 = -64+32 = -32; or, to convert 110 0000 (i.e., say -x) to decimal, first we find x, by complementing 110 0000, i.e., x = - (- x) = 2’s complement (110 0000) = 001 1111 +1 = 010 0000 = +32, => the result in decimal - x = -32… which was expected. Are there any overflows? There are no overflows since different sign numbers are added. How can a computer detect overflow? 1. Overflow = Carry7 Carry6 or 2. Overflow: Sign A • Sign B • (Sign result)’ + (Sign A)’ • (Sign B)’ • (Sign result) 1.4 The range of signed integers N expressed in 2-s complement representation that can be stored in a 10-bit register is: (a) -1024 ≤ N ≤ +1023 (b) -1023 ≤ N ≤+1024 (c) -512 ≤ N ≤ +511 (d) -511≤ N ≤ +512 (e) None of the above SOLUTION 1-bit for the Sign and 9 bits represent the number, so -29 ≤ N ≤ 29-1 (c) -512 ≤ N ≤ +511

1.5. Give the best binary approximation of A = (26.6)10 and B = - (23.4)10 using signed 2’scomplement representation with 2 bits for the fractional part. SOLUTION A= (26.6)10 ≈ A1 = 16+8+2+½ = +(11010.10)2 = (011010.10)2 = (26.5)10 … or ≈ A2 = 16+8+2+½+¼ = +(11010.11)2 =(011010.11)2 = (26.75)10 err1 =|A - A1| = |26.6 - 26.5| = 0.1; err2 = |A - A2| = |26.6 - 26.75| =0.15 Since err1 < err2, the best approximation of 26.610 = A ≈ A1 = 011010.102 B = -(23.4)10 ≈ B1 = -(16+4+2+1+½) = -(010111.10)2 = -b with b = +23.5 Note: Let’s assume that we don’t know how to find the 2’s-complement of a fractional negative number, so 1. we’ll consider b = (010111.10)2 = (010111.10)2 x 22/22 = (01011110)2/22 2. next we’ll find the 2’s-complement of (01011110)2 = (10100010)2 3. then we’ll divide it by 22 to scale back, such that => 2’s-complement of (010111.10)2 = (10100010)2/22 = (101000.10)2 = -23.5 = B1 or B ≈ B2 = - (16+4+2+1+¼ ) = - 010111.012 = 2’s-complement of (010111.01)2 = 101000.11)2 = 23.25; B1 = -23.5 is the closest to -23.4  B ≈ B1 = 101000.102

1.6. 1) Convert to decimal the following two numbers, 01010 & 10101, which are already expressed in 2’s complement representation. 2) These numbers are stored in two 6-bit registers X and Y to calculate their sum (S = X+Y) and their difference (D=X-Y) by using additions and 2’s complementation only. Convert to decimal and write each intermediate and final result, to check the correctness of your assertions. 3) Since both S and D have to be represented with 6 bits, indicate if overflow occurs, and explain how a circuit can detect these situations. SOLUTION 1) Since both numbers are already in 2’s complement representation, their values in decimal are:  010102 = +(23 + 21) = +1010 and  101012 = -24 + 22 + 20 = -16 + 4 + 1 = - 1110 or say 101012 = -y with y = -101012 = 2’s complement of (10101)2 = 010112 = 1110 101012 =-y= 1110 2) Using 2’s complement representation with 6 bits: +1010 = 0010102 => X and -11 10 = -(+11)10: -(001011)2 = 2’s complement(001011)2 =(110101)2 => Y Since –Y is needed too: -Y =2’s complement of(110101)2=(001011)2= (just to verify) = +1110 2’s complement representation

S= X+Y

Base 10 representation

6 5

4

3

2

1

0

CY: 0 0 0 X+ Y 1 1 S

0 0 1 1

0 1 0 1

0 0 1 1

0 1 0 1

0 0 1 1

+10 -11 -1

3) All numbers can be expressed with 6 bits, i.e.,

2’s complement representation

D=XY CY: X+ -Y D

Base 10 representation

6

5

4

3

2

1

0

0

0 0 0 0

1 0 0 1

0 1 1 0

1 0 0 1

0 1 1 0

0 0 1 1

+10 +11 +21

so NO overflow! OFL Detection

OFL = if (SgnX=SgnY) ≠SgnS, i.e., OFL = (SgnX.SgnY.SgnS’ + SgnX’.SgnY’.SgnS) = X5Y5S5’ + X5’Y5’S5 or if the most significant two carry bits are different: (Cy6’ . Cy5 + Cy6 . Cy5’ )= Cy6 ⊕ Cy5

1.7. Identify the decimal number which is represented next in floating point with the IEEE 754 11000010100010101100000000000000 standard: (a) (- 133.375)10 (c) (- 138.750)10 (e) (- 8.671875)10

(b) (- 69.375)10 (d) (- 34.6875)10

SOLUTION

S

E

 Find the “real” exponent, n n = E – 127 = 100001012 – 127 = (128+5) – 127 = 133 – 127 = 6  Put S, M, and n together to form the binary result (Don’t forget the implied “1” on the left of the mantissa.)

-1.0001010112 x 26 = -(1000101.011)2 64+5 2-2 2-3

It is (b) -(69.375)10

= 0.25 = 0.125 0.375

M...


Similar Free PDFs