Chapter 2: Data Representation
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 02n1.
    2. Signed magnitude.
      1. Use the left-most bit for the sign, usually 1 for negative.
      2. Range (2n11)2n11
      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 2nx in n bits.
      3. Easily computed as (2n1)x+1.
        Invert the bits and add 1.
      4. When doing arithmetic, the extra 2n falls off the left.
        (2nx)+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 2n12n11
      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 2n1x in n bits.
      3. Range 2n112n11
      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)2n1=2×2n12n1x=2n1x
    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 ab 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: 2i1+2i2++2ik is treated as 2i2ik.
          1. On the right end of a run of 1's, subtract the multiplicand (properly shifted): contributes 2ik.
          2. Just left of 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.
      6. Range of double:
    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. To allow many, many more characters so any language can be coded.
      1. Assigns “codepoints” (numbers) to any number of characters.
      2. Often said to be a 16-bit system, but there is no limit on the number of codepoints.
      3. Three encodings.
        1. Simplest is UTF-32. Just represent each character as a 32-bit number.
        2. UTF-8.
          1. Variable-length codes, multiples of 8 bits.
          2. A plain 7-bit ascii file is also a valid UTF-8 file. Keeps from breaking existing software.
        3. UTF-16.
          1. Variable size codes, minimum 16 bits.
          2. Used internally in some langauges and systems, but not often written to files.
  10. We will not cover the section on error detection and correction.

Questions

Chapter questions:
4th or 5th 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.