My UW

UW Search
Computer Science Home Page
Home
Contact Info
Lecture & Notes
Schedule
Computing
Grading
Examinations
Homework



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.

0110 0010
1001 1110

0011 1011
1100 0101

1001 1101
0110 0011

0011 1111
1100 0001
Problem 2 (4 points)
Convert the following 2's complement binary numbers to decimal numbers.

0111
= +(0111) = +7

1101
= (0011) = 3

01110
= +(01110) = +14

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, signmagnitude, 1's complement, and 2's complement.
Number  Unsigned  SignMagnitude  1's Complement  2's Complement 
28  00011100  00011100  00011100  00011100 
28  NA  10011100  11100011  11100100 
Problem 4 (6 points)

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 2^{n} >= 503. We can find this by trialanderror(2^{8} < 503 < 2^{9}) or by taking logarithms as follows: n = ceiling( log_{2} 503 ) = 9 bits.

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 = 2^{9}= 512
maximum number of people can be added to the village = 512  503 = 9
 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 = 2^{9} = 512
Maximum number of people in combined village = 256 + 512 = 768
Minimum number of bits required to represent 768 people uniquely is cieling(log_{2} 768 ) = 10 bits.
Problem 5 (4 points)

What is the largest positive number one can represent in a 8bit 2's complement code? Write your result in binary and decimal.
01111111 = 2^{7}  1 = 127

What is the greatest magnitude negative number one can represent in a 8bit 2's complement code? Write your result in binary and decimal.
10000000 = (10000000) = (2^{7}) = 128

What is the largest positive number one can represent in a 8bit 1's complement code? Write your result in binary and decimal.
01111111 = 2^{7}  1 = 127

What is the greatest magnitude negative number one can represent in a 8bit 1's complement code? Write your result in binary and decimal.
10000000 = (01111111) = (2^{7}1) = 127
Problem 6 (2 points)
Compute the followings:

NOT(1101) OR NOT(1100)
NOT(1101) = 0010
NOT(1100) = 0011
(0010) OR (0011) = (0011)

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.


