Homework 2 [Due at lecture on Wed, Sep 19]
Primary contact for this homework: Pradip Vallathol [pradip16 at cs dot wisc dot edu]
You must do this homework in groups of two. Please write the full name and the student id of each member on every page and staple multiple pages together.
Problem 1 (8 points)
Convert the following 2's complement binary numbers to decimal and hexadecimal representations. [The hexadecimal representation when converted into it corresponding binary string should represent the same 2's complement binary number as mentioned in the corresponding part. In other words, if you have to extend the 2's complement binary number before converting it into hexadecimal representation, you have to do so without changing its value.]
-
1001 - -7, 9
-
011101 - 29, 1D
-
010010110 - 150, 096
-
1101011001001 - -1335, FAC9
Problem 2 (6 points)
-
If I use an unconventional representation in which a decimal number is denoted by converting each digit into its binary form, how many bits would be necessary to represent the decimal number 318. [My representation is unambiguous, i.e., if I am given a binary string, there is one, and only one, decimal number that it would represent. If I had used minimum number of bits to represent each digit, my representation would become ambiguous. For example, if I had a binary string "1001", and I had used minimum number or bits for each digit, it could mean either 41 or 21 or 9. So now you have to reason how many bits I would have to allocate to each digit, in my representation, so that I have a unique representation of decimal numbers.]
Representation will be: 0011 0001 1000. So I will need 12 bits.
-
What is the minimum number of bits I would have required if I had represented decimal number 318 in binary form?
100111110, will need 9 bits [Credit will be given for 10 bits as well, since "unsigned binary" was not mentioned]
-
Is there a number that can be represented by using the same number of bits in my representation and in binary form (with minimum number of bits)?
8 or 9 [If you used 10 bits in part b, then your answer should be any number between 4 and 7]
The following (pair of) answers will also be accepted for parts (a) and (c): [Dropping the leftmost trailing 0's will also give a unique representation, but there is a reason we keep them, and always use 4 bits per digit. The representation described in this question is called "Binary Coded Decimal (BCD)". In case you are interested, you can read more about it on the internet.]
a. 11 0001 1000. So I will need 10 bits.
c. Any single digit number.
Problem 3 (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.
-
0101 + 0010
= 0111 (7); no overflow; 5 + 2 = 7
-
0111 - 1011
= 1100 (-4); overflow; 7 - (-5) = 12
-
1011 + 1101
= 1000 (-8); no overflow; (-5) + (-3) = (-8)
-
1010 - 0110
= 0100 (4); overflow; (-6) - 6 = (-12)
Problem 4 (2 points)
Compute the followings:
-
NOT(1101) OR (0110 AND 0111)
0010 OR 0110 = 0110
-
(1010 OR 0010) OR NOT(0010 AND 0110))
1010 OR NOT(0010) = 1010 OR 1101 = 1111
Problem 5 (4 points)
-
What is the largest positive number one can represent in a 6-bit 2's complement code? Write your result in binary and decimal.
011111 = 31
-
What is the greatest magnitude negative number one can represent in a 6-bit 2's complement code? Write your result in binary and decimal.
100000 = -32
-
What is the largest positive number one can represent in a 6-bit 1's complement code? Write your result in binary and decimal.
011111 = 31
-
What is the greatest magnitude negative number one can represent in a 6-bit 1's complement code? Write your result in binary and decimal.
100000 = -31
Problem 6 (4 points)
Write the decimal equivalents for these IEEE floating point numbers.
-
1 01111101 10000000000000000000000
-0.375
-
0 10000010 01100000000000000000000
11
Problem 7 (2 points)
Why is sign-extension important when adding binary numbers with representations of different lengths? Explain with the help of an example.
If 00110 + 101 (6 + (-3)) is done without sign-extension, and I treat the absence of a number as 0, I would get the result as 01011 (11) which is incorrect. If I sign-extended the numbers to have both binary numbers of equal length, I would get 00011 (3) which is the correct result.
|