Docsity

Solved Problems for Assignment 1 - Computer Organization I | CDA 3100, Assignments of Electrical and Electronics Engineering

Toggle sidebar
bg1
Problem 1.
Algorithm:
Assume that: + n is the number of given bits
+ flag is a Boolean variable
+ D = the number we wish to convert from decimal to binary
-Check if the number is not in [-2n, 2n-1] => overflow
-Else:
oIf the number < 0 then
Set flag = true
Add 1 to the number and change the sign of the number
# Convert the number into binary number
oFind P, such that 2P is the largest power of two smaller than D.
Repeat until P<0
If 2P<=D then
put 1 into column P
subtract 2P from D
Else
put 0 into column P
End if
Subtract 1 from P
o if flag = true then
invert every bit of the binary number
Decimal
number
8-bit two’s
complement
binary number
16-bit two’s complement binary
number
32-bit two’s complement
binary number
63 0011 1111 0000 0000 0011 1111 0000 0000 0000 0000
0000 0000 0011 1111
pf3
pf4
pf5

Partial preview of the text

Download Solved Problems for Assignment 1 - Computer Organization I | CDA 3100 and more Assignments Electrical and Electronics Engineering in PDF only on Docsity!

Problem 1.

Algorithm: Assume that: + n is the number of given bits

  • flag is a Boolean variable
  • D = the number we wish to convert from decimal to binary
  • Check if the number is not in [-2n, 2n-1] => overflow
  • Else: o If the number < 0 then  Set flag = true  Add 1 to the number and change the sign of the number

Convert the number into binary number

o Find P, such that 2P^ is the largest power of two smaller than D.  Repeat until P&lt;  If 2P&lt;=D then  put 1 into column P  subtract 2P^ from D  Else  put 0 into column P  End if  Subtract 1 from P o if flag = true then  invert every bit of the binary number

Decimal number 8-bit two’s complement binary number 16-bit two’s complement binary number 32-bit two’s complement binary number 63 0011 1111 0000 0000 0011 1111 0000 0000 0000 0000 0000 0000 0011 1111

-2,000 Overflow 1111 1000 0011 0000 1111 1111 1111 1111 1111 1000 0011 0000

Problem 2

N = 1111 1111 1111 1111 1111 1111 1110 1001 This is a negative number => We will find its complement: Substract 1 we have: 1111 1111 1111 1111 1111 1111 1110 1000 Invert every bit: 0000 0000 0000 0000 0000 0000 0001 0111 = -N  (^) -N = 2 (^4) +2 (^2) +2 (^1) +2 (^0) = 23  (^) N = -

  1. – 161 N = 1111 1111 1111 1111 1111 1111 0101 1111 This is a negative number, we can use the similar method in 1) to find the result.
  2. 2,147,483, N = 0111 1111 1111 1111 1111 1111 0101 1111 This is a positive number, we can use the following formula:  (^) N = 2 (^31) +2 (^30) +2 (^29) +2 (^28) +……+2 (^3) +2 (^2) +2 (^1) +2 0  (^) N = 2,147,483,

Problem 3

Decimal no. Single precision floating point no Double precision floating point no

  1. 20 0x41A00000 0x
  2. -5/6 0xB7555555 0Xbfeaaaaaaaaaaaa
  3. 0.2 0x3E4CCCCC 0x1FC 0 0 1 1 1 1 1 0

   

d  d d d d d

n n n n n i i i n n

=> So we have: F = 101010…1010 (52 bits) E = 1022ten = 011 1111 1110 (11 bits) Therefore the presentation is 1 011 1111 1110 1010 1010 1010 1010 1010 1010 1010 1010 1010 1010 1010 1010 1010 (0xBFA AAAA AAAA AAAA) 1) Similarly 2) Similarly Notes: N = 1.111 * 10- Since in the single precision, the smallest positive floating number is about  (^) N is too small to present  (^) underflow ( 1  0. 0 ) 2 (^1 ^127 ) 2 ^126  1. 175494351  10 ^38

Problem 4

a. Bias = 216-1^ -1 = 32767 b.

  • The largest positive number: (1+1-2-(64-1)) * 22^16 – 2 – 2^15 – 1^ = 2^32768 – 2^32704 = 1.41546*10 9864
  • The smallest positive number: (1+0.0)21-32767^ = 2-32766^ = 2.82593410- c. 20% more significant digits, and 9556 orders of magnitude more flexibility (exponent is 32 times larger).

Problem 5

sample program: #include #include union ieee754_hex{ unsigned int hex; struct{ unsigned int fraction:23; unsigned int exponent:8; unsigned int s:1; } ieee; }; int main(int argc, char *argv[]){ union ieee754_hex hexno;