------------------------------------------------------------------------------
MC logo
Chapter 2: Data Representation
[^] CSc 314 Home
------------------------------------------------------------------------------
[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]
[Booth's Algorithm Examples]
Omit Section 2.7, and the chapter appendix 2A.

Binary examples

  1. Bits, bytes and nibbles.
    1. Bits easy to represent physically.
    2. Group bits to make larger symbols.
    3. Eight bits is a byte.
    4. Half a byte is a nibble.
  2. Binary system.
    1. Standard numbers are base 10. Can use any base.
    2. Binary (base 2) works nicely with bits.
    3. Conversion between bases.
      1. To decimal
        1. By place value.
        2. By doubling (binary).
      2. From decimal
        1. By place value.
        2. By remainders.
    4. Octal and hexadecimal.
  3. Addition and subtraction in binary.
  4. Numbers are fixed in size.
    1. There finitely many of them.
    2. Overflow: Results maybe outside the representable range.
    3. There is a left-most bit.
  5. Signed and unsigned.
    1. Unsigned numbers. Range for n bits is 0  –  2n−1.
    2. Signed magnitude.
      1. Use the left-most bit for the sign, usually 1 for negative.
      2. Range −(2n−1−1)  –  2n−1−1
      3. Two ways to write zero.
      4. Operations must special-case on the sign bit.
    3. Two's complement.
      1. Usual representation these days.
      2. Represent −x as 2n − x in n bits.
      3. Easily computed as (2n−1) − x + 1.
        Invert the bits and add 1.
      4. When doing arithmetic, the extra 2n falls off the left.
        (2n − x) + x = 2n, but that bit falls off the left, so the result is zero.
        Takes advantage of the fixed size.
      5. A left bit of one identifies negative numbers.
      6. Range −2n−1  –  2n−1−1
      7. Zero is unique; extra negative value.
      8. Enlarge by extending the sign bit.
    4. One's complement.
      1. Older alternative to two's complement.
      2. Represent −x as 2n−1 − x in n bits.
      3. Range −2n−1−1  –  2n−1−1
      4. Negative and positive zero.
  6. Operations on fixed-size binary numbers.
    1. Change the representation size.
      1. Shortening
        1. Remove bits on the left.
        2. Accurate so long as the sign bit doesn't change, and no different bit is removed.
      2. Lengthening: Add copies of the sign bit at the left.
      3. Why does it work?
        1. For positive numbers, adding or removing zeros on the left does not change the value.
        2. Lengthen negative by one bit: (2nx) + 2n = 2×2nx = 2n+1x
        3. Shorten negative by one bit: (2nx) − 2n−1 = 2×2n−1−2n−1x = 2n−1x
    2. Addition.
      1. Carry-out: When the bit left of your number is a one.
      2. Overflow: When the result doesn't fit in your bit size.
      3. Unsigned numbers.
        1. Add normally.
        2. Carry-out is overflow.
      4. Two's complement.
        1. Add normally.
        2. Carry-out is not equivalent to overflow.
        3. Overflow is determined by sign.
          1. Adding a negative and a positive cannot overflow.
            Will be a carry-out if the result is positive.
          2. Adding two negatives or two positives is an overflow if the result has the wrong sign.
        4. Alternative: carry into the sign bit should equal the carry out.
    3. Subtraction.
      1. For two's complement, compute a − b as a + (−b)
      2. Same operation works for unsigned, but overflow is the lack of carry-out.
    4. Multiplication.
      1. Simple multiplication.
        1. Multiply by each digit in the multiplicand.
        2. Add the products allowing for place value.
        3. Must special-case negative multiplier.
      2. Booth's Algorithm.
        1. Works on tc without special case for negative.
        2. Treats runs of 1's as a group.
        3. A run of k one's: 2i−1 + 2i−2 + ... + 2ik is treated as 2i − 2ik.
          1. On the right end of a run of 1's, subtract the multiplicand (properly shifted): contributes −2ik.
          2. Just left the run, add the multiplicand, which contributes 2i.
          3. Some examples here, and more on pp. 80 and 81 in your text.
        4. Reduces the number of adds when there are runs of 1's.
        5. Can increase the number of adds when there are lots of single ones.
    5. Shifting multiplies (or divides) by powers of two.
  7. Floating point organization.
    1. Binary and fractional place values.
    2. Exponential notation, decimal and binary.
    3. Formats.
      Text simple format:
      S
      5 exp
      8 sig
      IEEE single
      precision:
      S
      8-bit exp
      23 significand bits
      IEEE double
      precision:
      S
      11-bit exp
      52 significand bits
      1. Signed-magnitude.
      2. Implied 1 on the significand (IEEE format).
      3. Biased exponent notation.
        1. Represent the exponent as the true value plus a constant bias.
        2. Allows negative exponents to be represented.
        3. Bias near the center of exponent range.
          1. 15 for book format.
          2. 127 for 32-bit IEEE.
          3. 1023 for 64-bit IEEE.
      4. Special values.
        ZeroAll zero bits
        +/- InfinityS 11111111 000...000
        NaNS 11111111 non-zero significand
      5. Designed so integer comparisons are correct.
    4. Errors accumulate.
    5. Basic math rules can be violated: a + (b + c) ≠ (a + b) + c for some values.
  8. Binary-coded decimal.
    1. Packed. Two digits per byte.
    2. Zoned, which is really just character data.
    3. Sometimes used for business calculations.
  9. Character codes.
    1. ASCII. 7-bit code often extended to 8.
    2. EBCDIC. IBM mainframes only. 8-bit code.
    3. Unicode. 16-bit code. (Not everyone speaks English.)
      1. Apparently, 16-bit isn't really the limit. It's just a common representation to allocate 16 bits for each character.
      2. I don't think there is a size limit. Just keep making up more codes as needed.
    4. UTF-8.
      1. A variable-length representation of the Unicode set.
      2. Backward compatible with ASCII.

Questions

Chapter questions:
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>>