arithmetic

    Cards (7)

    • basics of arithmetic
      -> binary values are input into a processor and the ALU determines results using logic circuits

      -> the fundamental of operations is addition

      signed binary = positive or negative values, shown by the left most bit
      (1 = -ve and 0 = +ve)

      unsigned binary = only positive values
    • binary addition
      rules:
      0 + 0 = 0
      0 + 1 = 1
      1 + 1 = 10 (the 1 carries to the next column)
      1 + 1 + 1 = 11

      eg 11110000 +
      10011111
      = 1 10001111 <- the extra bit is a result of overflow error
      (1 1 1) <- carrying
    • two's complement
      two's complement allows us to use binary for both positive and negative values

      to find the binary for a negative number you flip the bits and add 1
      1 -> first find the positive 01001101 = 77
      2 -> flip the digits 10110010
      3 -> add 1 10110011 = -77

      the number of combinations available (for 8 bit) is still 256 but half are positive and half negative so the max value is 127 and the min value is -128

      (2^n-1 ... (2^n-1) -1)
    • binary subtraction
      to subtract binary values we actually use addition and make use of two's complement.

      65 - 43 = 65 + - 43
      01000001 +
      11010101
      1 00010110 = 22 (you ignore the overflow bit)
    • overflow errors
      when the result is too large for the allocated number of bits, overflow will occur.
      The number may therefore be presented incorrectly
      A '1' as the first digit indicates a negative number so overflow occurs for any number above 127 (in 8 bit binary)
    • fixed point binary
      we can use binary to represent fractions using fixed points. using bits to the right of the units column (after the notional point ) introduces fractional values

      8 4 2 1 . 1/2 1/4 1/8 1/16
      0 1 0 1 . 1 1 0 0 = 5 3/4

      (fractional columns go up in negative powers of 2, 2^-2, 2^-3 etc)

      the placement of the binary point is fixed wih a specified number of bits each side
    • binary multiplication
      rules:
      0 * 0 = 0, 0 * 1 = 0, 1 * 1 = 1

      steps:
      1 -> multiply by the right most digit of the 2nd number
      2 -> put in a 0 on the right and repeat for the next value
      3 -> continue until all digits of the 2nd number have been multipliers
      4 - add together all the multiplied numbers

      eg 1010 * 101 = (1010, + 00000, + 101000) = 110010