You are on page 1of 3

CPSC2105 Assignment #1 Due 9/8/2005 before class begins

(show steps to get full credit)

1. (10 points) Convert the following integers to 8-bit unsigned binary representation.
a) 43 2|________43__ ……….1
2|_______21__ ………1
2|______10__ ………0
2|_____5___ ………1 -> 00101011
2|____2___ ……….0
2|___1___ ……….1
0
or: 43 = 32 + 11 = 32 + 8 + 2+1= 0x27+0x26+1x25+0x24+1x23+0x22+1x21+1x20
Thus we have 00101011

b) 231= 128 + 64 + 32 + 0 + 0 + 4 + 2 + 1 -> 11100111


7 6 5 4 3 2 1 0

2. (15 points) Convert the following integers to 8-bit signed (two’s-complement) binary.
a)
For positive number we just convert directly
37 = 0 + 0 + 32 + 0 + 0 + 4 + 0 + 1 -> 00100101

b) use the result from the last problem, first take the
00100101
1’s complement 11011010
+__________1
11011011 -> 11011011

c) First convert 125 to binary


125=64 + 32 + 16 + 8 + 4 + 0 + 1 -> 01111101
1’s complement 10000010
+___________1
10000011

3. (15 points) Convert the following integers to 16-bit signed (two’s-complement)


binary.
a) Since the sign is 0, just pad with 0’s
00100101 (8bit) -> 0000000000100101(16bit)
b) since we know –37 in 8-bit 2’s complement, we need to do the sign
extension
11011011 ( 8-bit) -> 1111111111011011 ( 16-bit)

c) likewise 10000011( 8-bit) -> 1111111110000011 (16-bit)

4. (10 points)Convert the following hexadecimal number to decimal numbers.


Use as many digits as necessary

a) 0xC220 as signed 2’s complement


0xC220 = 11000010001000002
1’s complement 0011110111011111
+ 1
00111101111000002 = 1584010
( 8192 + 4096 +2048 +1024 + 256+128+ 64 + 32 = 15840)
Since the sign bit is 1, final result is -15840.

b) 0x0BA0 as unsigned integer


0x0BA0 = 00001011101000002 = 297610
(2048 + 512 + 256 + 128 + 32)

5. (15 points) What is the range of decimal numbers that can be represented in:
a) 8–bit two’s–complement form? -27 to 27-1 (-128 to 127 )
b) 16–bit two’s–complement form? -215 to 215 (-32768 to 32767)
c) 8-bit unsigned form? 0 to 28-1 (0 to 255)

6. (15 points) Show the IEEE-754 single precision representation of the following real
numbers.
Use eight hexadecimal digits for your results.
a) 15.625
1510 = 11112
0.62510 =1/2 + 1/8 = 0.1012
thus 15.62510 = 1111.1012 = 1.111101 x 23
s = 0. p=3. p+127 = 130 = 128 + 2 = 1000000102. m=111101
-> 0 1000 0010 1111 0100 000 ….. = 0100 0001 0111 1010 …. = 0x417A0000

b) – 49.25
49 = 32 + 16 + 1 = 1100012
0.25 = ¼ = 0.012
49.2510 = 110001.012 = 1.1000101 x 25
P=5. P+127 = 128+4 = 100001002
S=1. M=1000101
IEEE-754 Single precision: 1 10000100 1000101 …….
Regroup =1100 0010 0100 0101 0000 … 00 = 0xC2450000

c) 0.0 special value 0x00000000

7. (10 points) Assuming 8-bit 2’s complement representation for the integers +70 and +
80, consider the following:
+70 = 010001102
+80 = 010100002
Add them together and the result is 100101102. Is this correct? Why or why not?

Answer: The result is wrong because of overflow

8. (10 points) The following two hexadecimal numbers represent real numbers
formatted according to the IEEE-754 single precision standard. Translate these to
decimal numbers.

a) C1541000
1100 0001 0101 0100 0001 000000000000 = 1 10000010 1010100000100..00

s=1
100000102 = 130 - 127, p = 3
m = 10101000001
binary = 1.10101000001 x 23 = 1101.01000001

approx. – 13.25

b) BAD2000
1011 1010 1101 0010 000000000000 = 1 01110101 101001 00000
s=1
011101012 = 117 P+127=127 -> P= -10
m = 101001
Binary = -1.101001 x 2-10 -> -1.6406265 x 2-10
≈ –1.6406265 x 10-10x0.30103 ≈ -1.6406265 x 10-3.0103
≈ -1.6022 x 10-3

You might also like