Bevin Shrestha

ID# 106003079

CSE 220

Homework #3 Part II

Due Date: November 05, 2008

 

 

 

PROBLEM A. Convert the following 2 signed integers from binary to Hexadecimal notation:
a.)11011110101011011011111011101111
Solution:
Given binary number is 1101 1110 1010 1101 1011 1110 1110 1111.
Lets group the four digits of binary number starting from left to right as follows:
(1111)2 = 1x 23 + 1x 22 +0x 21 +1x 20 = (15)10 = (F)16
(1110)
2 = 1x 23 + 1x 22 +1x 21 +1x 00 = (14)10 = (E)16
(1110)
2 = 1x 23 + 1x 22 +1x 21 +0x 20 = (14)10 = (E)16
(1011)
2 = 1x 23 + 0x 22 +1x 21 +1x 20 = (11)10 = (B)16
(1101)
2 = 1x 23 + 1x 22 +0x 21 +1x 20 = (13)10 = (D)16
(1010)
2 = 1x 23 + 0x 22 +0x 21 +0x 20 = (10)10 = (A)16
(1110)
2 = 1x 23 + 1x 22 +1x 21 +0x 20 = (14)10 = (E)16
(1101)
2= 1x 23 + 1x 22 +0x 21 +1x 20 = (13)10 = (D)16

Thus, (11011110101011011011111011101111)2 = (deadbeef)16

b.)00001011101011011011111011101111
Solution:
Given binary number is 0000 1011 1010 1101 1011 1110 1110 1111.
Lets group the four digits of binary number starting from left to right as follows:
(1111)
2 = 1x 23 + 1x 22 +0x 21 +1x 20 = (15)10 = (F)16
(1110)
2 = 1x 23 + 1x 22 +1x 21 +1x 00 = (14)10 = (E)16
(1110)
2 = 1x 23 + 1x 22 +1x 21 +0x 20 = (14)10 = (E)16
(1011)
2 = 1x 23 + 0x 22 +1x 21 +1x 20 = (11)10 = (B)16
(1101)
2 = 1x 23 + 1x 22 +0x 21 +1x 20 = (13)10 = (D)16
(1010)
2 = 1x 23 + 0x 22 +0x 21 +0x 20 = (10)10 = (A)16
(1011)
2 = 1x 23 + 0x 22 +1x 21 +1x 20 = (14)10 = (B)16
(0000)
2= 0x 23 + 0x 22 +0x 21 +0x 20 = (13)10 = (0)16

Thus, (00001011101011011011111011101111)2 = (0badbeef)16

PROBLEM B. Convert the following 2 signed real numbers from single floating point notation to hexadecimal.
a.) -0.0008162677986547351
The integral part is 0
10 = 02.
The fractional part is:
0.0008162677986547351 x 2 = 0.0016325355973094702
0.0016325355973094702 x 2 = 0.0032650711946189404
0.0032650711946189404 x 2 = 0.0065301423892378808
0.0065301423892378808 x 2 = 0.0130602847784757616
0.0130602847784757616 x 2 = 0.0261205695569515232
0.0261205695569515232 x 2 = 0.0522411391139030464
0.0522411391139030464 x 2 = 0.1044822782278060928
0.1044822782278060928 x 2 = 0.2089645564556121586
0.2089645564556121586 x 2 = 0.4179291129112243712
0.4179291129112243712 x 2 = 0.8358582258224487424
0.8358582258224487424 x 2 = 1.6717164516448974848
0.6717164516448974848 x 2 = 1.3434329032897949696
0.3434329032897949696 x 2 = 0.6868658065795899392
0.6868658065795899392 x 2 = 1.3737316131591798784
0.3737316131591798784 x 2 = 0.7474632263183597568
0.7474632263183597568 x 2 = 1.4949264526367195136
0.4949264526367195136 x 2 = 0.9898529052734390272
0.9898529052734390272 x 2 = 1.9797058105468780544
0.9797058105468780544 x 2 = 1.9594116210937561088
0.9594116210937561088 x 2 = 1.9188232421875122176
0.9188232421875122176 x 2 = 1.8376464843750244352
0.8376464843750244352 x 2 = 1.6752929687500488704
0.6752929687500488704 x 2 = 1.3505859375000977408
0.3505859375000977408 x 2 = 0.7011718750001954816
0.7011718750001954816 x 2 = 1.4023437500003909632
0.4023437500003909632 x 2 = 0.8046875000007819264
0.8046875000007819264 x 2 = 1.6093750000015638528
0.6093750000015638528 x 2 = 1.2187500000031277056
0.2187500000031277056 x 2 = 0.4375000000062554122
0.4375000000062554122 x 2 = 0.8750000000125108224
0.8750000000125108224 x 2 = 1.7500000000250216448
0.7500000000250216448 x 2 = 1.5000000000500432896
0.5000000000500432896 x 2 = 1.0000000001000865792

Thus, taking the integral part from the above obtained result, we get
(0.0008162677986547351)
10
= (0.000000000011010101111110101100111)
2
= 1.1010101111110101100111 x 10^-11

Sign = 1

Exponent = -11 + 127 = (116) = (01110100)2

Mantissa = (10101011111101011001110)2

So, (-0.0008162677986547351)10
= [1]sign [0111 0100]
exponent [101 0101 1111 1010 1100 1110]mantissa
= (BA55FACE)
16

b.) -9651108864
9651108864 – 2^33 = 1061174272

1061174272 – 2^29 = 524303360

524303360 – 2^28 = 255867904

255867904 – 2^27 = 121650176

121650176 – 2^26 = 54541312

54541312 – 2^25 = 20986880

20986880 – 2^24 = 4209664

4209664 – 2^22 = 15360

15360 – 2^13 = 7160

7160 – 2^12 = 3072

3072 – 2^11 = 1024

1024 – 2^10 = 0

The binary representation would be 1000111111010000000011110000000000

Let’s, normalize the number...

1000111111010000000011110000000000 = 1.000111111010000000011110000000000 x 233

Now we represent the individual parts...

Sign = 1 because the number is negative

Exponent = 33 + 127 = 160

Fraction = 1.000111111010000000011110000000000

Now we make our 32 bit representation...

1 10100000 00011111101000000001111 (That makes all 32 bits, the rest of the fraction is truncated).

1101 0000 0000 1111 1101 0000 0000 1111

= (d00fd00f)16

Problem C: Convert the following 2 signed real numbers from single floating point notation to hexadecimal. Show all work:

2.796762340086568 X 10-29
-5.056837726336028 x 10-10

 

a.) 2.796762340086568 X 10-29

We get the following after some calculations:

1 .00011011101000000001101 x 2-95

Now let’s represent the individual parts...

Sign = 0 because the number is positive

Exponent = -95 + 127 = 32

Fraction = 1 .00011011101000000001101

Now let’s make our 32 bit representation...

0 00100000 00011011101000000001101

0001 0000 0000 1101 1101 0000 0000 1101

= (100dd00d)16

 

 

b.) -5.056837726336028 x 10-10

We get the following after some calculations:

1 .00010110000000001010101 x 2-31

Now let’s represent the individual parts...

Sign = 1 because the number is negative

Exponent = -31 + 127 = 96

Fraction = 1 .00010110000000001010101

Now lets  make our 32 bit representation...

1 01100000 00010110000000001010101

1011 0000 0000 1011 0000 0000 0101 0101

= (b00b0055) 16

 

 

PROBLEM D. Convert the following 2 numbers from hexadecimal to single floating point notation.

a.)0xfeedface

Solution:
First of all, lets convert this number into a binary number.
(f)
16 = (15)10 = (1111)2
(e)
16 = (14)10 = (1110)2
(e)
16 = (14)10 = (1110)2
(d)
16 = (13)10 = (1111)2
(f)
16 = (15)10 = (1111)2
(a)
16 = (10)10 = (1010)2
(c)
16 = (12)10 = (1100)2
(e)
16 = (14)10 = (1110)2

Thus, [1]sign [11111101]exponent [1101111111110101100]mantissa

sign = negative
exponent - bias = 253 - 127 = 126
1 + fraction = 1 + (
2-1 + 2-2 + 2-4+ 2-5+ 2-6 + 2-7 + 2-8 + 2-9 + 2-10 + 2-11 + 2-12 + 2-13 + 2-15 + 2-16) = 1.874923706
Thus, Answer = -1.874923706 x 10
126

b.)0x0badfood

Solution:
First of all, lets convert this number into a binary number.
(0)16
= (0)10 = (0000)2
(b)
16 = (11)10 = (1011)2
(a)
16 = (10)10 = (1010)2
(d)
16 = (13)10 = (1101)2
(f)
16 = (15)10 = (1111)2
(0)
16 = (0)10 = (0000)2
(0)
16 = (0)10 = (0000)2
(d)
16 = (15)10 = (1111)2

Thus, [0]sign [00010111]exponent [01011011111000000001111]mantissa

sign = positive
exponent - bias = 23 - 127 = -104
1 + fraction = 1 + (
2-2 + 2-4 + 2-5+ 2-7+ 2-8 + 2-9 + 2-10 + 2-11 + 2-20 + 2-21 + 2-22 + 2-23) = 1.358888506
Thus, Answer = 1.358888506 x 10
-104

PROBLEM E. Add the following 2 signed hexadecimal integers by first converting them to binary.

a.)
0x10000fa5
0x0af50af5

Solution:
First of all, lets convert this hexadecimal number 0x10000fa5 into its equivalent binary number.
(1)16
= (0001)2
(0)
16 = (0000)2
(0)
16 = (0000)2
(0)
16 = (0000)2
(0)
16 = (0000)2
(f)16 = (1111)
2
(a)
16 = (1010)2
(5)
16 = (0101)2

Thus, 0x10000fa5 = (00010000000000000000111110100101)2

Similarly, lets convert this hexadecimal number 0x0af50af5 into its equivalent binary number.
(0)
16 = (0000)2
(a)16 = (1010)
2
(f)
16 = (1111)2
(5)
16 = (0101)2
(0)
16 = (0000)2
(a)
16 = (1010)2
(f)
16 = (1111)2
(5)
16 = (0101)2

Thus, 0x0af50af5 = (00001010111101010000101011110101)2

Now, let’s add (00010000000000000000111110100101)2 and (00001010111101010000101011110101)2.
That is,
(00010000000000000000111110100101)
2 + (00001010111101010000101011110101)2 = (11010111101010001101010011010)2

PROBLEM F. Add the following 2 signed hexadecimal integers by first converting them to binary.

a.)
0xfaded0af
0xfa1afe15

Solution:
First of all, let’s convert this hexadecimal number 0xfaded0af into its equivalent binary number.
(f)
16 = (1111)2
(a)
16 = (1010)2
(d)
16 = (1101)2
(e)
16 = (1101)2
(d)
16 = (1101)2
(0)
16 = (0000)2
(a)
16 = (1010)2
(f)
16 = (1111)2

Thus, 0xfaded0af = (11111010110111011101000010101111)2

Similarly, let’s convert this hexadecimal number 0xfa1afe15 into its equivalent binary number.
(f)16 = (1111)
2
(a)
16 = (1010)2
(1)
16 = (0001)2
(a)
16 = (1010)2
(f)
16 = (1111)2
(e)
16 = (1110)2
(1)
16 = (0001)2
(5)
16 = (0101)2

Thus, 0xfa1afe15 = (11111010000110101111111000010101)2

Now, let’s add (11111010110111011101000010101111)2 and (11111010000110101111111000010101)2.
That is,
(11111010110111011101000010101111)
2 + (111110100001101011111110000101011)2 = (10111011110001001111001100110011011010)2

PROBLEM G. Add the following 2 signed, single floating point numbers by first converting them to binary.
0x0000acdc
0x00abacab

Solution:
Translate to binary first...

0x 0 0 0 0 a c d c

0000 0000 0000 0000 1010 1100 1101 1100

0x 0 0 a b a c a b

0000 0000 1010 1011 1010 1100 1010 1011

Now let’s translate each of them to single floating point numbers...

0 00000000 00000001010110011011100

Sign = 0, so it is positive

Exponent = 0-127 = -127

Fraction = 1.00000001010110011011100

0 00000001 01010111010110010101011

Sign = 0, so it is positive

Exponent = 1-127 = -126

Fraction = 1.01010111010110010101011

Now, let’s add:

0.10000000101011001101110 x 2^-126 + 1.01010111010110010101011 x 2^-126 = 1.11011000000001100011001 x 2^126

Therefore the complete 32-bit representation of the added value is...

0 00000001 11011000000001100011001

Which can also be written as...

0000 0000 1110 1100 0000 0011 0001 1001

= (00ec0319) 16