next up previous
Next: Problem 3: Basically Annoying-Just Up: quiz1-ans Previous: Problem 1: Reason It

Problem 2: Some Utter: `` Numbers!!!''

  1. A computer with 6G (six gigabytes) of byte-addressable memory needs a minumum of 33 bits to label each byte with a unique address.

    Answer: True. You have to remember some powers of two. A gigabyte is $2^{30}$, but, the horror, six (6) is not an integral power of two. However, it's larger than $2^2$ and less than $2^3$. So 6GB will require at least $2^{33}=2^3 * 2^{30}$ bits.

  2. If a carry-out of one (1) occurs when adding a pair of 2's complement integers, then overflow has not occurred.

    Answer: False. Overflow in 2's complement only occurs when two numbers with the same sign are added together and produce a sum with a different sign. The carry out from the msb position may occur when overflow does, but is not an indicator of overflow in general.

  3. The C expression ((a < 0) ? (a + 15) : a) >> 16 is equivalent to $a/16$, where $a$ is declared to be an int.

    Answer: False. This is equivalent to dividing $a$ by 16, but only if we correct the shift-we want to do an arithmetic shift right by 4 (four), not 16.

  4. The C expression ( y + ((x - y) & -(x < y) ) returns the minimum of x and y.

    Answer: True. In order to see this, we will make a few intermediate variables.

    int ybig    = -(x < y);  \* all ones if   (x < y) is true , else 0 *\ 
    int diff_xy = (x-y);      \* sign = 1 if y < x, else sign is zero *\
    int bias = diff_xy & ybig; \* bias = 0  if y < x,  else  (x-y)*\
    return (y+bias)
    

Yeah, that was a lot of help. So, here is how this creature works. On a 32 bit machine.

Case ybig bias result
x < y 0xFFFF FFFF (x-y) x
x = y 0 0 y
x>y 0 0 y


next up previous
Next: Problem 3: Basically Annoying-Just Up: quiz1-ans Previous: Problem 1: Reason It
MM Hugue 2008-10-01