Practice Problems #1 - Fall 2011

Answer all parts of the following questions. Remember to click the submit button after entering answers to (all or some of) the questions.





  1. Fill in the missing entries. The first 5 lines have been filled in for you.

    n 2n (Decimal) 2n (Hex) 2n (Binary)
    0 1 0x1 1
    1 2 0x2 10
    2 4 0x4 100
    3 8 0x8 1000
    4 16 0x10 1 0000
    5 0x20 10 0000
    6 0x40 100 0000
    7 1000 0000
    8 1 0000 0000
    9 10 0000 0000
    10
    11
    12
  2. Convert the hex value 0x3F8C to binary.

    For example, hex value 0x5A7E converted to binary is 0101101001111110.

    hex A   7   E
    binary 0101 1010 0111 1110
    hex F   8   C
    binary
  3. Convert the following binary values to hex.

    Binary Hex
    01110010 0x72
    10110011
    100011
    01110010
    101110010

  4. Give the sum of these hex values:

    1. 0x13A
      0x001
    2. 0x13A
      0x071
    3. 0x13A
      0x077
  5. Assume the int type is stored in 32 bits (binary ). The machine is byte addressable and a byte is 8 bits.

    So an int value is stored in 4 consecutive byte addresses.

    A 32 bit value expressed in hexadecimal uses 8 hex digits.

    For example, the int value 8202 in hex is 0x0000200A

    Assume this 4 byte value is stored at addresses 0x4000 - 0x4003.

    Fill in the table below if the machine is little endian.

    (Each address should contain 1 byte = 2 hex digits, of the int value.)

    Address Stored Byte
    0x4000
    0x4001
    0x4002
    0x4003

  6. What is the output of the following C program?

    
    #include <stdio.h>
    #include <stdlib.h>
    
    void printSum(char x, char y);
    
    int main()
    {
      printf("\nAdding to char integer -126:\n");
      printSum(-126, -1);
      printSum(-126, -2);
      printSum(-126, -3);
      printSum(-126, -4);
    
      printf("\nAdding to char integer +126:\n");
      printSum(126, 1);
      printSum(126, 2);
      printSum(126, 3);
      printSum(126, 4);
    
      return 0;
    }
    
    void printSum(char x, char y)
    {
      char sum;
    
      sum = x + y;
      printf("%d + %d = %d\n", x, y, sum);
    }
    

    Answer:

  7. What char integer value should be added to the char integer -128 to get 0?

    (Remember: char integer values are: -128 to +127)

    Answer: