Software Developers View of Hardware Binary Arithmetic
Binary Addition The steps used for a computer to complete addition are usually greater than a human, but their processing speed is far superior.  RULES 0 + 0 = 0  0 + 1 = 1 1 + 0 = 1 1 + 1 = 0 (With 1 to carry) 1 + 1 + 1 = 1 (With 1 to carry)
Binary Addition EXAMPLE 1  0  0  1 1  0  1  1 +
Binary Addition EXAMPLE 1  0  0 1  1 1  0  1  1 0 +
Binary Addition EXAMPLE 1  0 1  0 1  1 1  0  1  1 0  0 +
Binary Addition EXAMPLE 1  0 1  0 1  1 1  0  1  1 1   0  0 +
Binary Addition EXAMPLE   1 1  0 1  0 1  1 1  0  1  1 0  1   0  0 +
Binary Addition EXAMPLE   1 1  0 1  0 1  1 1  0  1  1 1 0  1   0  0 +
Binary Addition CHECK THE ANSWER   9 11 20 +
Activity 1 Perform the following additions in binary. 101 10  + 40 10  = 320 10  + 18 10  = 76 10  + 271 10  =
Binary Subtraction Computers have trouble performing subtractions so the following rule should be employed: “ X – X is the same as X + -X” This is where two’s complement is used.
Binary Subtraction RULES Convert the number to binary. Perform two’s complement on the second number. Add both numbers together.
Binary Subtraction EXAMPLE 1 Convert 12 - 8 using two’s complement. Convert to binary 12 = 00001100 2 8  = 00001000 2 Perform one’s complement on the 8 10 00001000 2 11110111 2
Binary Subtraction EXAMPLE 1 Perform two’s complement. 1 1 1 1 0 1 1 1 2 0 0 0 0 0 0 0 1 2 1 1 1 1 1 0 0 0 2 Add the two numbers together. = 1 0 0 0 0 0 1 0 0 2  (Ignore insignificant bits) +
Binary Subtraction EXAMPLE 2  What happens if the first number is larger than the second? Try 6 10  - 10 10
Binary Subtraction EXAMPLE 2  Convert to binary 6 = 00000110 2 10  = 00001010 2 Perform one’s complement on the 10 10 00001010 2 11110101 2
Binary Subtraction EXAMPLE 2  Perform two’s complement.   1 1 1 1 0 1 0 1 2   0 0 0 0 0 0 0 1 2 = 1 1 1 1 0 1 1 0 2 +
Binary Subtraction EXAMPLE 2  Add the two numbers together. 0 0 0 0 0 1 1 0 2 1 1 1 1 0 1 1 0 2   = 1 1 1 1 1 1 0 0 2  (Ends with a negative bit) +
 
Binary Subtraction EXAMPLE 2  Perform one’s complement on the result 1 1 1 1 1 1 0 0 2   0 0 0 0 0 0 1 1 2 Add 1 to the result. 0 0 0 0 0 0 1 1 2 0 0 0 0 0 0 0 1 2 = 0 0 0 0 0 1 0 0 2 +
Binary Subtraction EXAMPLE 2  We then add the sign bit back. 0 0 0 0 0 1 0 0 2 = 1 0 0 0 0 1 0 0 2
Activity 2 Perform the following subtractions. 22 - 8 = 76 - 11 = 6 - 44 =
Binary Multiplication Multiplication follows the general principal of shift and add. The rules include: 0 * 0 = 0 0 * 1 = 0 1 * 0 = 0 1 * 1 = 1
Binary Multiplication EXAMPLE 1 Complete 15 * 5 in binary. Convert to binary 15 = 00001111 2 5  = 00000101 2 Ignore any insignificant zeros. 00001111 2 00000101 2 x
Binary Multiplication EXAMPLE 1 Multiply the first number. 1 1 1 1 2   1 0 1  2 1 1 1 1 Now this is where the shift and takes place. x 1111 x 1 = 1111
Binary Multiplication EXAMPLE 1 Shift one place to the left and multiple the second digit. 1 1 1 1 2   1 0 1  2 1 1 1 1 0 0 0 0 0 x 1111 x 0 = 0000 Shift One Place
Binary Multiplication EXAMPLE 1 Shift one place to the left and multiple the third digit. 1 1 1 1 2   1 0 1  2 1 1 1 1 0 0 0 0 0 1 1 1 1 0 0 x 1111 x 1 = 1111 Shift One Place
Binary Multiplication EXAMPLE 1 Add the total of all the steps.   1 1 1 1 0 0 0 0 0 1 1 1 1 0 0  1 0 0 1 0 1 1 Convert back to decimal to check. +
Activity 3 Calculate the following using binary multiplication shift and add. 12 * 3 = 1 0 0 1 0 0 2   13 * 5 = 1 0 0 0 0 0 1 2   97 * 20 = 1 1 1 1 0 0 1 0 1 0 0 2   121 * 67 = 1 1 1 1 1 1 0 1 0 1 0 1 1 2
Binary Division Division in binary is similar to long division in decimal. It uses what is called a shift and subtract method.
Binary Division EXAMPLE 1 Complete 575 / 25 using long division. 0 02 How many times does 25 go into 57? TWICE 25  575 Take the first digit of 575 (5) and see if 25 will go into it.  If it can not put a zero above and take the next number. 25  575
Binary Division Drop down the next value 25  575 50 75 How much is left over? 57 – (25 * 2) = 7 25  575 50 7 02 02
Binary Division 023 023 Check for remainder 75 – (3 * 25) = 0 FINISH! 25  575 50 75 75 0 Divide 75 by 25 Result = 3 25  575 50 75
Binary Division Complete the following: 25/5 Step 1:  Convert both numbers to binary. 25 = 1 1 0 0 1 5 = 1 0 1 Step 2:  Place the numbers accordingly: 1 0 1  1 1 0 0 1
Binary Division Step 3:  Determine if 1 0 1 (5) will fit into the first bit of dividend. 1 0 1  1 1 0 0 1 1 0 1(5) will not fit into 1(1) Step 4:  Place a zero above the first bit and try the next bit.
Binary Division Step 5:  Determine if 1 0 1 (5) will fit into the next two bits of dividend. 1 0 1  1 1 0 0 1 1 0 1(5) will not fit into 1 1(3) Step 6:  Place a zero above the second bit and try the next bit. 0
Binary Division Step 7:  Determine if 1 0 1 (5) will fit into the next three bits of dividend. 1 0 1  1 1 0 0 1 1 0 1(5) will fit into 1 1 0(6) Step 8:  Place a one above the third bit and times it by the divisor (1 0 1) 0 0
Binary Division Step 9:  The multiplication of the divisor should be placed under the THREE bits you have used. 1 0 1  1 1 0 0 1   1 0 1 A subtraction should take place, however you cannot subtract in binary. Therefore, the two’s complement of the 2 nd  number must be found and the two numbers added together to get a result. 0 0 1
Binary Division Step 10:  The two’s complement of 1 0 1 is 0 1 1 1 0 1  1 1 0 0 1   0 1 1   0 0 1 0 0 1 +
Binary Division Step 11:  Determine if 1 0 1 will fit into the remainder  0 0 1. The answer is no so you must bring down the next number. 1 0 1  1 1 0 0 1   0 1 1   0 0 1 0 0 0 1 +
Binary Division Step 12:  1 01 does not fit into 0 0 1 0. Therefore, a zero is placed above the last bit. And the next number is used. 1 0 1  1 1 0 0 1   0 1 1   0 0 1 0 1 0 0 1 + 0
Binary Division Step 13:  1 0 1 does fit into 1 0 1 so therefore, a one is placed above the final number and the process of shift and add must be continued. 1 0 1  1 1 0 0 1   0 1 1   0 0 1 0 1 0 1 1 0 0 0 0 0 1 + 0 1 +
Binary Division Step 14:  The final answer is 1 0 1 (5) remainder zero.
Activity 4 Complete the following divisions: 340 / 20 580 / 17
Activity 5 40/4 36/7

Binary Arithmetic

  • 1.
    Software Developers Viewof Hardware Binary Arithmetic
  • 2.
    Binary Addition Thesteps used for a computer to complete addition are usually greater than a human, but their processing speed is far superior. RULES 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 0 (With 1 to carry) 1 + 1 + 1 = 1 (With 1 to carry)
  • 3.
    Binary Addition EXAMPLE1 0 0 1 1 0 1 1 +
  • 4.
    Binary Addition EXAMPLE1 0 0 1 1 1 0 1 1 0 +
  • 5.
    Binary Addition EXAMPLE1 0 1 0 1 1 1 0 1 1 0 0 +
  • 6.
    Binary Addition EXAMPLE1 0 1 0 1 1 1 0 1 1 1 0 0 +
  • 7.
    Binary Addition EXAMPLE 1 1 0 1 0 1 1 1 0 1 1 0 1 0 0 +
  • 8.
    Binary Addition EXAMPLE 1 1 0 1 0 1 1 1 0 1 1 1 0 1 0 0 +
  • 9.
    Binary Addition CHECKTHE ANSWER 9 11 20 +
  • 10.
    Activity 1 Performthe following additions in binary. 101 10 + 40 10 = 320 10 + 18 10 = 76 10 + 271 10 =
  • 11.
    Binary Subtraction Computershave trouble performing subtractions so the following rule should be employed: “ X – X is the same as X + -X” This is where two’s complement is used.
  • 12.
    Binary Subtraction RULESConvert the number to binary. Perform two’s complement on the second number. Add both numbers together.
  • 13.
    Binary Subtraction EXAMPLE1 Convert 12 - 8 using two’s complement. Convert to binary 12 = 00001100 2 8 = 00001000 2 Perform one’s complement on the 8 10 00001000 2 11110111 2
  • 14.
    Binary Subtraction EXAMPLE1 Perform two’s complement. 1 1 1 1 0 1 1 1 2 0 0 0 0 0 0 0 1 2 1 1 1 1 1 0 0 0 2 Add the two numbers together. = 1 0 0 0 0 0 1 0 0 2 (Ignore insignificant bits) +
  • 15.
    Binary Subtraction EXAMPLE2 What happens if the first number is larger than the second? Try 6 10 - 10 10
  • 16.
    Binary Subtraction EXAMPLE2 Convert to binary 6 = 00000110 2 10 = 00001010 2 Perform one’s complement on the 10 10 00001010 2 11110101 2
  • 17.
    Binary Subtraction EXAMPLE2 Perform two’s complement. 1 1 1 1 0 1 0 1 2 0 0 0 0 0 0 0 1 2 = 1 1 1 1 0 1 1 0 2 +
  • 18.
    Binary Subtraction EXAMPLE2 Add the two numbers together. 0 0 0 0 0 1 1 0 2 1 1 1 1 0 1 1 0 2 = 1 1 1 1 1 1 0 0 2 (Ends with a negative bit) +
  • 19.
  • 20.
    Binary Subtraction EXAMPLE2 Perform one’s complement on the result 1 1 1 1 1 1 0 0 2 0 0 0 0 0 0 1 1 2 Add 1 to the result. 0 0 0 0 0 0 1 1 2 0 0 0 0 0 0 0 1 2 = 0 0 0 0 0 1 0 0 2 +
  • 21.
    Binary Subtraction EXAMPLE2 We then add the sign bit back. 0 0 0 0 0 1 0 0 2 = 1 0 0 0 0 1 0 0 2
  • 22.
    Activity 2 Performthe following subtractions. 22 - 8 = 76 - 11 = 6 - 44 =
  • 23.
    Binary Multiplication Multiplicationfollows the general principal of shift and add. The rules include: 0 * 0 = 0 0 * 1 = 0 1 * 0 = 0 1 * 1 = 1
  • 24.
    Binary Multiplication EXAMPLE1 Complete 15 * 5 in binary. Convert to binary 15 = 00001111 2 5 = 00000101 2 Ignore any insignificant zeros. 00001111 2 00000101 2 x
  • 25.
    Binary Multiplication EXAMPLE1 Multiply the first number. 1 1 1 1 2 1 0 1 2 1 1 1 1 Now this is where the shift and takes place. x 1111 x 1 = 1111
  • 26.
    Binary Multiplication EXAMPLE1 Shift one place to the left and multiple the second digit. 1 1 1 1 2 1 0 1 2 1 1 1 1 0 0 0 0 0 x 1111 x 0 = 0000 Shift One Place
  • 27.
    Binary Multiplication EXAMPLE1 Shift one place to the left and multiple the third digit. 1 1 1 1 2 1 0 1 2 1 1 1 1 0 0 0 0 0 1 1 1 1 0 0 x 1111 x 1 = 1111 Shift One Place
  • 28.
    Binary Multiplication EXAMPLE1 Add the total of all the steps. 1 1 1 1 0 0 0 0 0 1 1 1 1 0 0 1 0 0 1 0 1 1 Convert back to decimal to check. +
  • 29.
    Activity 3 Calculatethe following using binary multiplication shift and add. 12 * 3 = 1 0 0 1 0 0 2 13 * 5 = 1 0 0 0 0 0 1 2 97 * 20 = 1 1 1 1 0 0 1 0 1 0 0 2 121 * 67 = 1 1 1 1 1 1 0 1 0 1 0 1 1 2
  • 30.
    Binary Division Divisionin binary is similar to long division in decimal. It uses what is called a shift and subtract method.
  • 31.
    Binary Division EXAMPLE1 Complete 575 / 25 using long division. 0 02 How many times does 25 go into 57? TWICE 25 575 Take the first digit of 575 (5) and see if 25 will go into it. If it can not put a zero above and take the next number. 25 575
  • 32.
    Binary Division Dropdown the next value 25 575 50 75 How much is left over? 57 – (25 * 2) = 7 25 575 50 7 02 02
  • 33.
    Binary Division 023023 Check for remainder 75 – (3 * 25) = 0 FINISH! 25 575 50 75 75 0 Divide 75 by 25 Result = 3 25 575 50 75
  • 34.
    Binary Division Completethe following: 25/5 Step 1: Convert both numbers to binary. 25 = 1 1 0 0 1 5 = 1 0 1 Step 2: Place the numbers accordingly: 1 0 1 1 1 0 0 1
  • 35.
    Binary Division Step3: Determine if 1 0 1 (5) will fit into the first bit of dividend. 1 0 1 1 1 0 0 1 1 0 1(5) will not fit into 1(1) Step 4: Place a zero above the first bit and try the next bit.
  • 36.
    Binary Division Step5: Determine if 1 0 1 (5) will fit into the next two bits of dividend. 1 0 1 1 1 0 0 1 1 0 1(5) will not fit into 1 1(3) Step 6: Place a zero above the second bit and try the next bit. 0
  • 37.
    Binary Division Step7: Determine if 1 0 1 (5) will fit into the next three bits of dividend. 1 0 1 1 1 0 0 1 1 0 1(5) will fit into 1 1 0(6) Step 8: Place a one above the third bit and times it by the divisor (1 0 1) 0 0
  • 38.
    Binary Division Step9: The multiplication of the divisor should be placed under the THREE bits you have used. 1 0 1 1 1 0 0 1 1 0 1 A subtraction should take place, however you cannot subtract in binary. Therefore, the two’s complement of the 2 nd number must be found and the two numbers added together to get a result. 0 0 1
  • 39.
    Binary Division Step10: The two’s complement of 1 0 1 is 0 1 1 1 0 1 1 1 0 0 1 0 1 1 0 0 1 0 0 1 +
  • 40.
    Binary Division Step11: Determine if 1 0 1 will fit into the remainder 0 0 1. The answer is no so you must bring down the next number. 1 0 1 1 1 0 0 1 0 1 1 0 0 1 0 0 0 1 +
  • 41.
    Binary Division Step12: 1 01 does not fit into 0 0 1 0. Therefore, a zero is placed above the last bit. And the next number is used. 1 0 1 1 1 0 0 1 0 1 1 0 0 1 0 1 0 0 1 + 0
  • 42.
    Binary Division Step13: 1 0 1 does fit into 1 0 1 so therefore, a one is placed above the final number and the process of shift and add must be continued. 1 0 1 1 1 0 0 1 0 1 1 0 0 1 0 1 0 1 1 0 0 0 0 0 1 + 0 1 +
  • 43.
    Binary Division Step14: The final answer is 1 0 1 (5) remainder zero.
  • 44.
    Activity 4 Completethe following divisions: 340 / 20 580 / 17
  • 45.