Advanced Placement Computer Science AB:
Solutions 1
    Sewickley Academy, 2000-2001

See Course Home Page.

1a.  Express -41 in 11-bit 2's complement

41         = 00000101001
complement = 11111010110
add one    = 11111010111 = -41
b.  Express -603 in 4-bit 2's complement
Not possible.
c.  Express -73 in 8-bit 2's complement
73         = 01001001
complement = 10110110
add one    = 10110111 = -73
d.  Express 61 and -34 in 9-bit 2's complement, then express their sum also in 2's complement.
61         = 000111101
34         = 000100010
complement = 111011101
add one    = 111011110 = -34

 61 =   000111101
-34 = + 111011110
        ---------
        000011011 = 1 + 2 + 8 + 16 = 27

2.  Write a brief, but clear, tutorial explaining negation in 2's complement.  You can submit your tutorial in any reasonable format (A Word document, a PDF file, a web page, etc).  Web pages are most preferred, actually, but any format will get equal grading.
Any correct description of the process received full credit for this problem.  "The process" is to complement the bits and then add one, as shown repeatedly in the solutions to problem 1 above.
3.  Consider the hexadecimal number AC17
a.  Express it in base 10
AC17 = 7 + 16 * (1 + 16 * (12 + 16 * (10)))
     = 7 + 16 * (1 + 16 * 172)
     = 7 + 16 * 2753
     = 44,055
b.  Express it in binary (base 2)
AC17 = 1010 1100 0001 0111
c.  Assuming this is ASCII, what characters does it represent?
Because ASCII is a 7-bit code, and 0xAC has its high-order bit set, it is not a valid ASCII code.  Another way to say this is that ASCII codes are 0-127, and since 0xAC equals 172, it is not valid.  Regarding 0x17, though, that equals 23, which is ctrl-w, and is also known as ETB.
d.  Assuming it is a 2-byte 2's complement number, what number does it represent?
AC17       = 1010 1100 0001 0111
complement = 0101 0011 1110 1000
add one    = 0101 0011 1110 1001  ;; This is the negation of AC17
           =   5    3    E    9
           = 9 + 16 * (14 + 16 * (3 + 16 * (5)))
           = 21,481

Thus, the answer is the negation of this value, or -21,481.

e.  Assuming it is a 2-byte unsigned integer, what number does it represent?
This is actually the same as question as question 3a:  44,055.
f.  Assuming it is a floating-point number (as described in our text), what number does it represent?.
AC17 = 1010 1100 0001 0111

For a floating point number, we actually need 4 bytes, so we assume the second byte is 0, giving us:

AC170000 = 1010 1100 0001 0111 0000 0000 0000 0000

Thus,
  sign bit = 1 (this is a negative float)
  exponent = 010110002 - 127
           = (8 + 16 + 64) - 127
           = -39
  mantissa = 1.00101112

It is unclear from the question what format the answer must be in -- binary or decimal.  In binary, we already have the answer now:

  -1.00101112 x 2-39 = -0.00000000000000000000000000000000000000100101112

Converting this to decimal is left as an exercise for the reader, but suffice it to say that this is a very tiny number.

See Course Home Page.