Chapter 2: Data Representation

[Chapter 1: Introduction]
[Chapter 2: Data Representation]
[Chapter 3: Boolean Algebra and Digital Logic]
[Chapter 4: MARIE: A Very Simple Architecture]
[386 Assembler Language]
[Chapter 5: Real-World Architectures]
[Chapter 6: Memory Systems]
[Chapter 7: I/O Systems]
[Chapter 9: Alternative Architecture]
[Chapter 11: Performance Measurement]

Omit Section 2.7, and the chapter appendix 2A.

- Bits, bytes and nibbles.
- Bits easy to represent physically.
- Group bits to make larger symbols.
- Eight bits is a byte.
- Half a byte is a nibble.

- Binary system.
- Standard numbers are base 10. Can use any base.
- Binary (base 2) works nicely with bits.
- Conversion between bases.
- To decimal
- By place value.
- By doubling (binary).

- From decimal
- By place value.
- By remainders.

- To decimal
- Octal and hexadecimal.

- Addition and subtraction in binary.
- Numbers are fixed in size.
- There finitely many of them.
- Overflow: Results maybe outside the representable range.
- There is a left-most bit.

- Signed and unsigned.
- Unsigned numbers. Range for
*n*bits is 0 – 2*n*−1. - Signed magnitude.
- Use the left-most bit for the sign, usually 1 for negative.
- Range −(2
*n*−1−1) – 2*n*−1−1 - Two ways to write zero.
- Operations must special-case on the sign bit.

- Two's complement.
- Usual representation these days.
- Represent −
*x*as 2*n*−*x*in*n*bits. - Easily computed as (2
*n*−1) −*x*+ 1.

*Invert the bits and add 1.* - When doing arithmetic, the extra 2
*n*falls off the left.

(2*n*−*x*) +*x*= 2*n*, but that bit falls off the left, so the result is zero.

*Takes advantage of the fixed size.* - A left bit of one identifies negative numbers.
- Range −2
*n*−1 – 2*n*−1−1 - Zero is unique; extra negative value.
- Enlarge by extending the sign bit.

- One's complement.
- Older alternative to two's complement.
- Represent −
*x*as 2*n*−1 −*x*in*n*bits. - Range −2
*n*−1−1 – 2*n*−1−1 - Negative and positive zero.

- Unsigned numbers. Range for
- Operations on fixed-size binary numbers.
- Change the representation size.
- Shortening
- Remove bits on the left.
- Accurate so long as the sign bit doesn't change, and no different bit is removed.

- Lengthening: Add copies of the sign bit at the left.
- Why does it work?
- For positive numbers, adding or removing zeros on the left does not change the value.
- Lengthen negative by one bit:
(2
*n*−*x*) + 2*n*= 2×2*n*−*x*= 2*n*+1−*x* - Shorten negative by one bit:
(2
*n*−*x*) − 2*n*−1 = 2×2*n*−1−2*n*−1−*x*= 2*n*−1−*x*

- Shortening
- Addition.
- Carry-out: When the bit left of your number is a one.
- Overflow: When the result doesn't fit in your bit size.
- Unsigned numbers.
- Add normally.
- Carry-out is overflow.

- Two's complement.
- Add normally.
- Carry-out is not equivalent to overflow.
- Overflow is determined by sign.
- Adding a negative and a positive cannot overflow.

*Will be a carry-out if the result is positive.* - Adding two negatives or two positives is an overflow if the result has the wrong sign.

- Adding a negative and a positive cannot overflow.
- Alternative: carry into the sign bit should equal the carry out.

- Subtraction.
- For two's complement, compute
*a*−*b*as*a*+ (−*b*) - Same operation works for unsigned, but overflow is the
*lack*of carry-out.

- For two's complement, compute
- Multiplication.
- Simple multiplication.
- Multiply by each digit in the multiplicand.
- Add the products allowing for place value.
- Must special-case negative multiplier.

- Booth's Algorithm.
- Works on tc without special case for negative.
- Treats runs of 1's as a group.
- A run of
*k*one's: 2*i*−1 + 2*i*−2 + ... + 2*i*−*k*is treated as 2*i*− 2*i*−*k*.- On the right end of a run of 1's, subtract the multiplicand
(properly shifted): contributes −2
*i*−*k*. - Just left the run, add the multiplicand, which
contributes 2
*i*. - Some examples here, and more on pp. 80 and 81 in your text.

- On the right end of a run of 1's, subtract the multiplicand
(properly shifted): contributes −2
- Reduces the number of adds when there are runs of 1's.
- Can increase the number of adds when there are lots of single ones.

- Simple multiplication.
- Shifting multiplies (or divides) by powers of two.

- Change the representation size.
- Floating point organization.
- Binary and fractional place values.
- Exponential notation, decimal and binary.
- Formats.
Text simple format:S5 exp8 sigIEEE single

precision:S8-bit exp23 significand bitsIEEE double

precision:S11-bit exp52 significand bits- Signed-magnitude.
- Implied 1 on the significand (IEEE format).
- Biased exponent notation.
- Represent the exponent as the true value plus a constant bias.
- Allows negative exponents to be represented.
- Bias near the center of exponent range.
- 15 for book format.
- 127 for 32-bit IEEE.
- 1023 for 64-bit IEEE.

- Special values.
Zero All zero bits +/- Infinity S 11111111 000...000 NaN S 11111111 non-zero significand - Designed so integer comparisons are correct.

- Errors accumulate.
- Basic math rules can be violated:
*a*+ (*b*+*c*) ≠ (*a*+*b*) +*c*for some values.

- Binary-coded decimal.
- Packed. Two digits per byte.
- Zoned, which is really just character data.
- Sometimes used for business calculations.

- Character codes.
- ASCII. 7-bit code often extended to 8.
- EBCDIC. IBM mainframes only. 8-bit code.
- Unicode. 16-bit code. (Not everyone speaks English.)
- Apparently, 16-bit isn't really the limit. It's just a common representation to allocate 16 bits for each character.
- I don't think there is a size limit. Just keep making up more codes as needed.

- UTF-8.
- A variable-length representation of the Unicode set.
- Backward compatible with ASCII.

4th ed: 1, 2, 16, 20, 23, 27, 32, 34, 36, 43, 51.

3rd ed: 1, 2, 6, 8, 10, 25, 33.

Consider the 8-bit twos complement number 11100101. What does it look like as 16-bit?

Consider the number (positive) 56. What is the smallest number of bits that can be stored in as a twos complement number?

Express the number 48713 as packed BCD in 32 bits.

Chapter 1: Introduction | Chapter 3: Boolean Algebra and Digital Logic |