Exam 1 Review Questions - Part 1 (with Answers)

This is representative of the kinds of topics and kind of questions you may be asked on the exam. In addition to this practice exam, you should also review:

Questions

  1. The leftmost bit of a 32-bit number is in what position?
    Answer:
               31
             


  2. Shifting an unsigned binary number N two positions to the left is equivalent to multipling N by what (in decimal)?
    Answer:
               4 (each shift to the left is another multiplication by two, so 22)
             


  3. Shifting an unsigned binary number N four positions to the right is equivalent to performing truncating division (ignoring the remainder) by what (in decimal)?
    Answer:
              16 (each shift to the right is another division by two, so 24)
             


  4. For ANY unsigned binary number, which bit must you look at in order to determine if the number is odd or even?
    Answer:
    		Bit 0 (the rightmost bit)
    		


  5. What is -8 in twos complement representation? Represent your solution using 8 bits.
    Answer:
    8 in binary: 0000 1000
    flip bits:   1111 0111
    add 1:       1111 1000
    1111 1000
    	


  6. What is 1 + 1 with a carry-in bit set?
    Answer:
      1
      1
    + 1
    ---
      1 with carry-out set  
    	


  7. What is 1 + 1 without a carry-in bit set?
    Answer:
      0
      1
    + 1
    ---
      0 with carry-out set 
    	


  8. What is 1 + 0 without a carry-in bit set?
    Answer:
      0
      1
    + 0
    ---
      1 without carry-out set 
    	


  9. What is:

      11111101
    + 01000101
    	

    Specify if the result has a carry-out set and if the result sets the overflow bit.

    Answer:
    	1 11111010 
    	  11111101
    	+ 01000101
    	----------
    	  01000010
    
    	Carry-out set, overflow bit not set. 
    


  10. What is:

      10010110
    - 11101010
    

    Specify if the result has a carry-out set and if the result sets the overflow bit.

    Answer:
      10010110
    - 11101010
    
    ...is equivalent to...
    
        10010110
    + (-11101010)
    
    Original:  11101010
    Flip bits: 00010101
    Instead of adding 1 here, I'll set the carry-in bit for the add
    
    0 00101111
      10010110
    + 00010101
    ----------
      10101100
    
    Carry-out not set, overflow bit not set.
    	


  11. Consider an unknown binary number N. Using only bitwise operations and bitmasks, give an expression that will produce N, except that bit 7 is guaranteed to be one. Express any bitmasks using 2-digit hexadecimal.
    Answer:
    
    We have a binary number that looks like this:
    XXXX XXXX
    
    ...where X is an unknown bit.
    We want to produce a binary number that looks like this:
    
    1XXX XXXX
    
    We'll need to use OR (|) for this, as OR can be forced to produce 1
    as a result with an unknown number as with ((X | 1) = 1).
    This same reasoning gives us the bitmask to OR with.
    We end up with:
    
      XXXX XXXX
    | 1000 0000
    -----------
      1XXX XXXX
    
    1000 0000 in hexadecimal is 0x80.
    So overall we have:
    
    N | 0x80