The following notes refer to material from Chapter 1.
Number Representation & Machine Memory:
Recall (see section 1.2) that machine memory is a collection of circuits each capable of storing a binary digit. Also, memory is usually organized into groups of eight (or sixteen, or thirty two etc.) bits (a word) each of which is given a unique address. It is the word size of the machine that determines, and limits, number representation.
Integer representation (section 1.6):
Positive and negative integers are represented in either excess or two's complement notation. To illustrate we assume a word size of four bits. We start with excess notation.
The following procedure differs from that presented in the text and is presented here as a possibly simpler alternative.
The real benefit of two's complement is that it allows easy implementation
of binary arithmetic. That is, binary addition and subtraction may be
easily accommodated by designing an addition circuit only. To accomplish
subtraction, merely represent the number to be subtracted in two's
complement form and add.
e.g. 410 -
610 may be written as
410 +
(-610) =
-210. In binary this becomes 0100 + 1010 = 1110
Notice that our four bit word system allows integers ranging from -8 to +7. In general, a k bit word will accommodate integers ranging from -2k-1 to +2k-1-1. For example, an 8 bit word would allow integers ranging from -128 to 127. Similarly, modern workstations, which have a word size of 32 bits, allow integers ranging from -2147483648 to +2147483647.
Practice problems:
See page 53 #1 and page 54 #2a, #2d and #2f.
Overflow: (page 51)
Since word size is fixed, it is possible that an addition or subtraction may lead to a result that is too large to be accommodated. For example, in our four bit system, 510 + 410 = 910 but in binary this becomes 0101 + 0100 = 1001. However, in two's complement, 1001 is NOT 910 but -710. This is the overflow problem. Similarly, -710 - 310 = -1010. Using two's complement this becomes 1001 + 1101 = 0110. Notice that we discard the excess carry bit. However, in two's complement, 0110 is NOT -1010 but 610.
Tip: Overflow only occurs when adding two numbers of the same sign. We may use this fact to help in determining if overflow has occurred. Merely examine the sign bit of the result of the addition. If it is different then overflow has occurred.
Floating-Point notation:
To represent scientific (or floating-point) notation in a fixed bit system we must decide how to partition the word into bits for the sign, exponent and mantissa. Also, since the exponent may be positive or negative, a representation scheme must be used for the exponent. Excess notation is typically used.
To illustrate, consider an eight bit word (Fig 1.24) where the leftmost bit is the sign bit, the next three bits the exponent bits and the remaining four bits the mantissa bits.
Truncation/Round-off Errors: (page 57)
Consider the case where we want to represent 2.625 in floating point notation using our eight bit scheme. Since 2.62510 = 10.1012 = 0.10101 | 2 then since we can accommodate at most four bits for the mantissa the floating-point representation is 0 110 1010. Observe that this is 2.510 and so we have introduced round-off error.
Practice problems:
See page 59 #1 and #2 (#1a, c, d and #2a, b, d will be solved in class).