HOMEWORK # 2 SOLUTIO
Problem 1 (2 points)
a. There are 313 characters in the Tamil language. If every character is to be encoded into
a unique bit pattern, what is the minimum number of bits required to do this?
8 bits can used to encode 28 = 256 characters and 9 bits can be used to encode 29 =
512 characters. So, we would need 9 bits.
b. How many more characters can be accommodated in the language without requiring
additional bits for each character?
512 – 313 = 199
Problem 2 (4 points)
Convert the following 2's complement binary numbers to decimal numbers.
a. 1010
First bit is 1. So it is a –ve number. 2’s complement of 1010 = 0101 + 1 = 0110. So the
answer is -6.
b. 0010
This is a +ve number since it starts with 0 Answer is 2.
c. 111111
This is a –ve number since it starts with 1. Its 2’s complement is 000000 + 1 = 000001.
So the answer is -1
d. 011111
This is a +ve number since it starts with 0. The answer is 31.
Problem 3 (4 points)
a. What is the largest positive number one can represent in a 16-bit 2's complement
code? Write your result in binary and decimal.
0111 1111 1111 1111 binary and 215 - 1 = 32767 decimal
b. What is the greatest magnitude negative number one can represent in a 16-bit 2's
complement code? Write your result in binary and decimal.
1000 0000 0000 0000 binary and -215 = -32768 decimal
c. What is the largest positive number one can represent in a 16-bit signed magnitude
code? Write your result in binary and decimal.
0111 1111 1111 1111 binary and 215 - 1 = 32767 decimal
d. What is the greatest magnitude negative number one can represent in a 16-bit signed
magnitude code? Write your result in binary and decimal.
1111 1111 1111 1111 binary and –(215 – 1) = -32767 decimal
Problem 4 (2 points)
What are the 8-bit patterns used to represent each of the characters in the string "This Is
Easy!"? (Only represent the characters between the quotation marks.)
Character Hex (from ASCII table) Binary equivalent
T 54 0101 0100
h 68 0110 1000
i 69 0110 1001
s 73 0111 0011
Space 20 0010 0000
I 49 0100 1001
s 73 0111 0011
Space 20 0010 0000
E 45 0100 0101
a 61 0110 0001
s 73 0111 0011
y 79 0111 1001
! 21 0010 0001
Problem 5 (4 points)
Convert the following decimal numbers to 8-bit 2's complement binary numbers. If there is
problem while doing this, describe it.
a. 102
0110 0110
b. 64
0100 0000
c. 128
Does not fit in an 8-bit signed number
d. -128
1000 0000
Problem 6 (4 points)
The following binary numbers are 4-bit 2's complement binary numbers. Which of the
following operations generate overflow? Justify your answers by translating the operands
and results into decimal.
a. 0111 + 1101
No overflow.
0111
1101
--------
10100
Answer is 0100 binary = 4 decimal [7 + (-3)]
b. 1001 + 1110
Overflow.
1001
1110
--------
10111
Answer is 0111 binary = 7 decimal. But actual answer is -9 [(-7) + (-2)]
c. 1111 + 1001
No overflow.
1111
1001
--------
11000
Answer is 1000 binary = -8 decimal [(-1) + (-7)]
d. 0011 + 0101
Overflow.
0011
0101
--------
1000
Answer is 1000 binary = -8 decimal. But actual answer is 8 [3 + 5]
Problem 7 (2 points)
A computer programmer wrote a program that adds two numbers. The programmer ran
the program and observed that when 5 is added to 8, the result is the character m. Explain
why this program is behaving erroneously.
The error that is occurring here is that 5 and 8 are being interpreted as characters ‘5’ and ‘8’
respectively. As a result, the addition that is taking place is not 5 + 8; rather, it is ‘5’ + ‘8’. If we
look up values in the ASCII table, 5 is 0x35 and 8 is 0x38. 0x35 + 0x38 = 0x6d, which is the
ASCII value for ‘m’.
Problem 8 (2 points)
Compute the following:
a. OT(1011) OR (1011)
NOT(1011) = 0100
Answer = (0100) OR (1011) = 1111
b. OT(1001 AD (0100 OR 0110))
0100 OR 0110 = 0110
1001 AND 0110 = 0000
Answer = NOT(0000) = 1111
Problem 9 (4 points)
Write the decimal equivalents for these IEEE floating point numbers.
a. 0 01111111 11000000000000000000000
Sign bit is 0 (+ve).
Exponent = 127.
Fraction = 1*2-1 + 1*2-2 = 0.75
Answer = (+) 1.fraction * 2exponent – 127
= 1.75 * 20 = 1.75
b. 1 01111101 10000000000000000000000
Sign bit is 1 (-ve).
Exponent = 125.
Fraction = 1*2-1 = 0.5
Answer = (-) 1.fraction * 2exponent – 127
= - 1.5 * 2-2 = - 0.375
Problem 10 (2 points)
Given a black box which takes n bits as input and produces one bit for output, what is the
maximum number of unique functions that the black box can implement? (Hint: Try to
visualize a truth table for a single function of n bits. Determine how many rows such a
truth table has. Then determine how many combinations are possible with the number of
rows that you just found)
Consider a single function that this black box implements. If there are n binary inputs,
the truth table contains 2n rows.
Now, each of these rows in the truth table can be filled with 0 or 1. The number of ways
in which we can fill in these rows (using 0 and 1) gives us the number of unique
functions. Since each of the rows can be filled in using 2 possible values and since the
number of rows is 2n, the number of ways = 2 power (2n).