COMP1521 18s1 COMP1521 18s1 Final Exam Comp Sys Fundamentals
[Instructions] [Documentation]
[Q1] [Q2] [Q3] [Q4] [Q5] [Q6] [Q7] [Q8] [Q9] [Q10]

Question 4 (4 marks)

In the following questions, assume that the type

typedef unsigned short int Bits;

represents a 16-bit unsigned bit-string.

A constant of type Bits could be written as e.g. 0xffff (which would have all bits set to one) or 0x0000 (which would have all bits set to zero).

  1. If the following assignments have been made:

    Bits x = 0x1234;
    Bits y = 0xfedc;
    

    then what are the values of the following expressions:

    1.   (x | y)

    2.   (x & y)

    3.   (x ^ y)

    4.   (~ x)

    Write your answers as 16-bit binary bit-strings (e.g. 1001000011110101).

  2. Describe in words what the following function does:

    void f(Bits *x, Bits*y)
    {
    	*y = *x ^ *y;
    	*x = *x ^ *y;
    	*y = *x ^ *y;
    }
    

    Answers that include the phrase "bitwise exclusive-OR" are worth zero marks. Don't just say literally what the statements do; describe the overall effect of the function.

    If you need a concrete example to help with your description consider the following usage of the function:

    Bits a = 0x1234;
    Bits b = 0x4321;
    f(&a, &b);
    

Type your answers to this question into the appropriate place in the q4.txt file, and submit it using the command:

submit q4

This will make a copy of the q4.txt file as your answer for this question. You can run the submit command as many times as you like, but only the most recent submission will be marked.