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

Question 5 (6 marks)

In the questions below, write all your answers as bit-strings. Hexadecimal, decimal and octal are not acceptable.

  1. Assume that the variable x is an unsigned short quantity, represented as a 16-bit bit-string. Give the final value of x after each of the sequence of statements is executed.

    1.   x = 1234;   (note: decimal)

    2.   x = ~0xF5E3;   (bitwise one's complement)

    3.   x = 5; x &= 71;

    4.   x = 0xFFFF; x++;

  2. Give a UTF-8 encoding, using as many bits as necessary, for each of the following characters (whose string and Unicode encoding is given):

    1.   '!' == U+00021

    2.   '£' == U+000A3

    3.   'ℜ' == U+0211C

    4.   '𝓍' == U+1D4CD

  3. Consider the following type definition:

    union _four {
    	unsigned short us;
    	short          ss;
    	char           ch;
    	char           st[2];
    };
    

    and the code:

    union _four abc;   abc.us = 0x3264;
    

    Give, using an appropriate number of bits, the value of each of the following expressions:

    1.   abc.us

    2.   abc.ss

    3.   abc.ch

    4.   abc.st[1]

    Hint: the command "man 7 ascii" will help to translate ascii codes to characters.

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

submit q5

This will make a copy of the q5.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.