Pre-Lab Assignment: Lab 5     Name _____________________________________

Show all work!!!!

  1. Convert the base 10 number 102 to base 2.

     

     

     

  2. Find the 8-bit two's complement representation of each of the following (your answer to #1 will help):

    1. 102     ________________________________________

    2. -102    ________________________________________

     

  3. Convert the base 10 number 508 to base 9:

     

     

  4. Find the base 10 value of each of the following 8-bit two's complement numbers:

    1. 11011101

       

       

    2. 01110100

     

     

  5. Convert the base 8 number 32758 to
    1. base 10

       

       

    2. base 2 (using the special relationship between base 8 and base 2)

       

       

  6. What is the largest positive base 10 integer (unsigned -- all places are used for the number with no sign) that can be represented in four base 6 digits? Write both the 4-digit base 6 number and find its value in base 10.

     

     

     

  7. The 8-bit two's complement representation of 107 is 01101011 and the representation of 52 is 00110100.
    1. Find the 8-bit sum (two's complement) of 107 and 52.
                 0 1 1 0 1 0 1 1
               + 0 0 1 1 0 1 0 0
               ------------------
      					<---- your answer
               __________________
      
      
    2. Convert the answer to base 10 (remember the answer is a two's complement number).

       

       

       

       

    3. Did overflow occur? Explain.

       

       

       

  8. Suppose gpa is a variable containing the grade point average of a student. Suppose the goal of the program is to let a student know if he/she made the Dean's list (the gpa must be 3.5 or above). Write an if... else... statement that prints out the appropriate message (either "Congratulations -- you made the Dean's List" or "Sorry you didn't make the Dean's List").

     

     

     

     

  9. As activity directory at Lake Lazydays Resort, it is your job to suggest appropriate activities to guests based on the weather. You recommend that when the temperature is greater than 95 or less than 20 people should visit the resort shops. Otherwise you recommend the following activities:
      temp >= 80:         swimming
      60 <= temp < 80:    tennis
      40 <= temp < 60:    golf   
      20 <= temp < 40:    skiing 
    
    Fill in the blanks in the code below as directed in the comments. The if should be a cascading if with conditions that are no more complicated than necessary.
      int temp;
      System.out.println("What's the temperature today?");
      temp = scan.nextInt();
    
      // Declare a boolean variable extremeTemp and assign it an
      // expression that is true when the temperature is greater than 95 or
      // less than 20
    
      __________________________________________________________________________;
    
      // Complete the cascading if (points will be deducted for unnecessary 
      // comparisons - use the boolean variable declared above where appropriate)
    
      if ( __________________________________________ )
    
        System.out.println ("Visit our shops!");
    
      else if ( _______________________________________________ )
    
        System.out.println("How about a dip in the pool?");
    
      _______________________________________________________
    
        System.out.println("Go grab a racquet!");
    
      _______________________________________________________
    
        System.out.println("It's a perfect day for golf.");
    
      _______________________________________________________
    
        System.out.println("Let's hit the slopes!");