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

See Course Home Page.

When possible, SHOW YOUR WORK.

1.  What is the largest positive and smallest negative numbers possible in:

a.  5-bit 2's complement notation
largest positive = 01111 = +15
smallest negative = 10000 = -16
b.  7-bit 2's complement notation
largest positive = 0111111 = +63
smallest negative = 1000000 = -64
2.  Express -71.34375 in 32-bit floating point notation
a) Sign bit = 1 (this is negative)
b) 71 = 64 + 4 + 2 + 1 = 10001112
c) 0.34375 = 1/4 + 1/16 + 1/32 = 0.010112
d) 71.034375 = 1000111.010112 = 1.000111010112  x 26
e) exponent+127 = 133 = 128 + 4 + 1 = 100001012
g) [sign,exp+127,mantissa-san-leading-1] = 1 10000101 000111010112
h) g with proper spacing and trailing 0's = 1100 0010 1000 1110 1011 0000 0000 00002
3.  Consider the hexadecimal number 4162:
a.  Express it in base 10
0x4162 = (256 * (4 * 16 + 1))   +   (6 * 16 + 2)  = (256 * 65) + 98 = 16,738
b.  Express it in binary (base 2)
  4    1    6    2
0100 0001 0110 00102
c.  Assuming this is ASCII, what characters does it represent?
0x41 = 65 which is A
0x62 = 98 which is b
Thus, it is the string Ab
d.  Assuming it is a 2-byte 2's complement number, what number does it represent?
This is the same as part a: 16,738.
e.  Assuming it is a 2-byte unsigned integer, what number does it represent?
Because the high-order bit (the sign bit) is 0, this is also the same as part a:  16,738.
f.  Assuming it is a floating-point number (with trailing 0's as needed to pad to 32 bits), what number does it represent?
a) Express in base 2:  0100 0001 0110 00102
b) Sign bit = 0, so positive
c) Exp+127 = 100000102 = 128 + 2 = 130, so exp = 3
d) mantissa-sans-leading 1 = .1100102
e) Put this together to get:  1.110012 * 23 = 1110.012 = 8 + 4 + 2 + 1/4 = 14.25
See Course Home Page.