Computer Sciences Dept.

CS/ECE 252 Introduction to Computer Engineering

Fall 2011 Section 1
Instructor Guri Sohi
TAs Newsha Ardalani and Rebecca Lam

URL: http://www.cs.wisc.edu/~sohi/cs252/Fall2011/

Homework 2 // Due at lecture Fri, Sep 16

Primary contact for this homework: Newsha Ardalani [newsha 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 pages and staple multiple pages together.

Problem 1 (4 points)

Find the 2's complement of the following binary numbers.

  1. 0110 0010
    1001 1110
  2. 0011 1011
    1100 0101
  3. 1001 1101
    0110 0011
  4. 0011 1111
    1100 0001

Problem 2 (4 points)

Convert the following 2's complement binary numbers to decimal numbers.

  1. 0111
    = +(0111) = +7
  2. 1101
    = -(0011) = -3
  3. 01110
    = +(01110) = +14
  4. 111010
    = -(000110) = -6

Problem 3 (8 points)

Using 1 byte (8 bits) to represent each number, write the binary representations of 28 and -28 in unsigned, sign-magnitude, 1's complement, and 2's complement.

NumberUnsignedSign-Magnitude1's Complement2's Complement
2800011100000111000001110000011100
-28NA100111001110001111100100

Problem 4 (6 points)

  1. Assume that there are exactly 503 occupants in a village. If every person is to be assigned a unique bit pattern, what is the minimum number of bits required to do this?
    Let n be the minimum number of bits required, then by definition it is the smallest integer such that 2n >= 503. We can find this by trial-and-error(28 < 503 < 29) or by taking logarithms as follows: n = ceiling( log2 503 ) = 9 bits.
  2. How many more people can be added to the village population without requiring additional bits for each person's unique id?
    maximum number of people represtable uniquely with 9 bits = 29= 512
    maximum number of people can be added to the village = 512 - 503 = 9
  3. Suppose that for village A, we need 8 bits to represent everyone uniquely. Similarly for village B, we need 9 bits. If both villages are combined into one big village, What is the minimum number of bits required to represent everyone uniquely in the combined village?
    Maximum number of people in village A = 2 8 = 256
    Maximum number of people in village B = 29 = 512
    Maximum number of people in combined village = 256 + 512 = 768
    Minimum number of bits required to represent 768 people uniquely is cieling(log2 768 ) = 10 bits.

Problem 5 (4 points)

  1. What is the largest positive number one can represent in a 8-bit 2's complement code? Write your result in binary and decimal.
    01111111 = 27 - 1 = 127
  2. What is the greatest magnitude negative number one can represent in a 8-bit 2's complement code? Write your result in binary and decimal.
    10000000 = -(10000000) = -(27) = -128
  3. What is the largest positive number one can represent in a 8-bit 1's complement code? Write your result in binary and decimal.
    01111111 = 27 - 1 = 127
  4. What is the greatest magnitude negative number one can represent in a 8-bit 1's complement code? Write your result in binary and decimal.
    10000000 = -(01111111) = -(27-1) = -127

Problem 6 (2 points)

Compute the followings:

  1. NOT(1101) OR NOT(1100)
    NOT(1101) = 0010
    NOT(1100) = 0011
    (0010) OR (0011) = (0011)
  2. NOT(1000 AND (1100 OR 0101))
    (1100 OR 0101) = 1101
    1000 AND 1101 = 1000
    NOT(1000) = 0111

Problem 7 (1 points)

Describe what conditions indicate overflow has occurred when two 2's complement numbers are added.

  • When adding two numbers, overflow occurs when the two operands have the same leftmost bit and the leftmost bit of the answer is different.
    When the operands have differing leftmost bits, overflow cannot occur when adding them together because we are adding a positive number with a negative number which means we are actually subtracting. It implies that the result cannot be bigger than the operands. So there is no possibility of overflow in this case. The leftmost bit is frequently referred to as the Most Significant Bit (MSB for short).
  • carry into MS bit does not equal carry out

Problem 8 (1 points)

Convert the following bit sequence into hexadecimal
1111101011001110000011111111

  • starting from the left, split the number into groups of 4 bits.
    1111 1010 1100 1110 0000 1111 1111
  • For each group of 4 bits, use the conversion table to find the hexadecimal value.
    1111 = 0xF, 1010 = 0xA, 1100 = 0xC, 1110 = 0xE, 0000 = 0x0
    The given value in hex is 0xFACE0FF.

 
Computer Sciences | UW Home