============================================
Notes and answers for Lab 07 (computer math)
============================================
- Ian! D. Allen - idallen@idallen.ca - www.idallen.com
Not all questions will be marked - check all your answers against this
answer sheet:
References: ECOA2e Section 2.5.3, 2.5.5, 2.5.6, 2.6.3, 2.6.4,
3.2.1-3.2.4 and associated Chapter Slides
Class Notes under http://teaching.idallen.com/cst8214/07f/
binary_math.txt Binary Mathematics, unsigned, two's complement, etc.
hexadecimal_conversions.txt Converting to/from hexadecimal (base 16)
overflow.txt Calculating the OVERFLOW flag in binary arithmetic
ieee754_conversions.txt Converting to/from IEEE 754 floating point format
You can check your work using any online converter; use Google to find one.
e.g. http://www.tonymarston.net/php-mysql/converter.php
http://www.h-schmidt.net/FloatApplet/IEEE754.html
A quiz is here: http://acc6.its.brooklyn.cuny.edu/~gurwitz/core5/binquiz.html
Base 36: http://www.cut-the-knot.org/recurrence/word_primes.shtml
Many bases: http://www.cut-the-knot.org/binary.shtml
1.What happens to the value of a binary number if you "shift" the
bits to the right one place by deleting the rightmost binary digit,
e.g. 11012 --> 1102 [divide by base (two), discard remainder; i.e. "half"]
2.What happens to the range of values possible in a word if you increase
the word length by one bit, e.g. from eight bits to nine bits or from
100 bits to 101 bits? [multiply by base (two); i.e. "doubles"]
3.In the simplified floating-point model used in the text, the significand
can only store eight bits of precision. Why can't the decimal value
128.5 be accurately represented in eight bits? (Section 2.5.3)
[128.5 needs nine bits of precision; one bit is lost]
4.IEEE 754 single-precision floating-point can store numbers in the
approximate range of 2**-127 to 2**+127. Look up or use a calculator to
express this range (approximately) as powers of ten (decimal).
[approx. 10**-38 up to +10**38]
[The above question is badly worded - a "range" is from the smallest
negative number to the largest positive number. The range should be
given above as -2**127 to +2**127 or -10**38 to +10**38 (approximately).]
5.What is the approximate decimal range (powers of ten) of IEEE 754
double-precision floating-point numbers (Figure 2.3, p.70)?
[approx. -10**308 up to +10**308]
6.What is floating-point overflow? (p.70, Chapter 2 Slide 81)
[the desired value has an exponent greater than the largest allowed exponent,
i.e. the magnitue of the number is too big, e.g. 1.0 x 10**50]
7.What is floating-point underflow? (p.70, Chapter 2 Slide 81)
[the desired value has an exponent smaller than the smallest allowed
exponent, i.e. the number is too close to zero, e.g. 1.0 x 10**-50]
8.What serious mathematical error can occur due to floating-point
underflow? (Chapter 2 Slide 81) [divide by zero]
9.Give a decimal example of a floating-point number that would cause
overflow if you tried to represent it as an IEEE 754 single-precision
floating-point number: [anything significantly over 10**38, e.g. 10**40
or -10**40. Note that since these are decimal approximations, (10**38)+1
isn't sufficiently large to overflow.]
10.Give an example of a floating-point number that would cause
underflow if you tried to represent it as an IEEE 754 single-precision
floating-point number: [anything significantly closer to zero than
10**-38, e.g. 10**-40]
11.Why do the decimal numbers 2147483775 (0x8000007F) and 2147483648
(0x80000000) both convert to the same IEEE 754 single-precision
floating-point number 0x4F000000 that has decimal value 2147483648.0?
(Hint: For a similar reason, in Section 2.5.3, the numbers 128 and 128.5
both convert to 128.0 when stored in the simplified floating-point format
used in the text.) [0x8000007F requires 32 bits of precision; the last
(rightmost) 9 bits are thrown away when converting, so the "7F" part of
0x8000007F disappears and it looks just like 0x800000]
12.True - floating point mathematics may not be associative
or distributive. (Section 2.5.6)
13.What is the correct way to test that floating-point value x is "equal"
to zero? (p.72) [something like: if ( abs(x) < 10**-20 ) then ...]
14.Give the range of unprintable ASCII "Control" characters in decimal
and hexadecimal. (Section 2.6.3) 0-31, 0x00-0x1F
15.How many bits are needed to represent the unprintable ASCII "Control"
characters? [32 numbers needs 5 bits (2**5 == 32)]
16.What is the name of the first printable character in the ASCII
character set? ["SP" or "Space" (with value 32, 040, or 0x20)]
17.The ASCII code for Z is decimal 90 (0x5A). Derive the code for CTRL-Z
in decimal and hex. [mask off the non-ctrl bits: 0x5A & 0x1F = 0x1A = 26]
18.If the ASCII code for Z is decimal 90 (0x5A), what is the code for
Y in decimal and hex? [90 - 1 = 89; 0x5A - 1 = 0x59]
19.What ASCII value do you get if you subtract the code for Space from
the code for lower-case m? (see Table 2.7 p.79) [0x6D - 0x20 = 0x4D = 'M']
20.Does the above subtraction transform work for all the lower-case
ASCII letters? [yes]
21.Represent the seven-bit ASCII character Z in eight bits using odd
parity. (Section 2.6.3) ['Z' = 0x5A = 1011010 --> 11011010 odd parity]
22.Represent the seven-bit ASCII control character CTRL-Z in eight bits
using odd parity. ['CTRL-Z' = 0x1A = 0011010 --> 00011010 odd parity]
23.You look into memory and you see the value 0x5A5A. How can you tell
if this is two ASCII letters or a numeric data value? [you cannot]
24.How many bytes does it take to store a Unicode character?
(Section 2.6.4) [two (16 bits per Unicodecharacter)]
25.True - the first 128 characters of Unicode (0x0000 to 0x007F) are
the same as ASCII. (p.80)
26.True - the Elvish script used in Tolkein's The Lord of the Rings
(Tengwar) is a proposed character set included in the Unicode standard.
( http://www.unicode.org/roadmaps/smp/ )
27.Construct a Boolean truth table for xyz + (xyz)' [where the prime
mark indicates complement]. (p.155) [see (1a) p.759]
28.Construct a Boolean truth table for x(yz'+x'y) [where the prime mark
indicates complement]. (p.155) [see (1b) p.759]
29.Give both versions of deMorgan's Law (p.113): [see Table 3.5 p.113]
30.Using deMorgan's Law, write an expression for the Boolean complement
of x(y'+z). (p.155 and Section 3.2.2-3.2.4) [see (3) p.759]
31.Using deMorgan's Law, write an expression for the Boolean complement
of xy+x'z+yz'. (Section 3.2.2-3.2.4)
[(xy + x'z + yz')' = (xy)'(x'z)'(yz')' = (x' + y')(x + z')(y' + z)]
32.Avoiding a Common Error: Use a truth table to show that (xy)' is not
equal to x'y' and (x+y)' is not equal to x'+y'. (i.e. "not red Jello"
is much more specific than "not red and not Jello".) (bottom p.113)
x y x' y' xy (xy)' x'y' x+y (x+y)' x'+y'
0 0 1 1 0 1 1 0 1 1
0 1 1 0 0 1 0 1 0 1
1 0 0 1 0 1 0 1 0 1
1 1 0 0 1 0 0 1 0 0