Download
two s complement n.
Skip this Video
Loading SlideShow in 5 Seconds..
Two’s Complement PowerPoint Presentation
Download Presentation
Two’s Complement

Two’s Complement

138 Views Download Presentation
Download Presentation

Two’s Complement

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Two’s Complement

  2. Two’s Complement • A system used to represent a negative number in binary • Positive numbers start with a 0 • Negative numbers start with a 1

  3. 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 8 9 9 9 9 9 9 9 7 9 9 9 9 9 9 9 6 On a cars Mileometer if you went backwards this would happen: 0 0 0 0 0 0 0 1 2 3 0

  4. Two’s Complement is like a Speedometer……. 128 64 32 16 8 4 2 1 0 0 0 0 0 0 1 1 = 3 Positive MSB (Most Significant Bit) indicated by 0

  5. Two’s Complement is like a Speedometer……. 128 64 32 16 8 4 2 1 0 0 0 0 0 0 1 0 = 2 Positive MSB indicated by 0

  6. Two’s Complement is like a Speedometer……. 128 64 32 16 8 4 2 1 0 0 0 0 0 0 0 1 = 1 Positive MSB indicated by 0

  7. Two’s Complement is like a Speedometer……. 128 64 32 16 8 4 2 1 0 0 0 0 0 0 0 0 = 0 Positive MSB indicated by 0

  8. Two’s Complement is like a Speedometer……. -128 64 32 16 8 4 2 1 1 1 1 1 1 1 1 1 = -1 Negative MSB indicated by 1

  9. Two’s Complement is like a Speedometer……. -128 64 32 16 8 4 2 1 1 1 1 1 1 1 1 0 = -2 Negative MSB indicated by 1

  10. Two’s Complement is like a Speedometer……. -128 64 32 16 8 4 2 1 1 1 1 1 1 1 0 1 = -3 Negative MSB indicated by 1

  11. How can you convert a negative two’s complement number to denary? Example: Convert two’s complement 10010110 -128 64 32 16 8 4 2 1 1 0 0 1 0 1 1 0 This would be: -128 + 16 + 4 + 2 = -106

  12. Example 2 Convert two’s complement 11011011 -128 64 32 16 8 4 2 1 1 1 0 1 1 0 1 1 This would be: -128 + 64 + 16 + 8 + 2 + 1 = -37

  13. Activity Convert the following numbers to denary: • Two’s complement 00110011 • Two’s complement 11001100 • Two’s complement 10111101 • Binary (no +\- MSB at the start) 11110101

  14. How can you convert a negative denary number into two’s complement? Step 1 pretend negative denary number is positive and convert it into binary e.g. -52 becomes 52 128 64 32 16 8 4 2 1 0 0 1 1 0 1 0 0

  15. How can you convert a negative denary number into two’s complement? Step 2 Starting from the right, leave all digits alone, up to and including the first 1, then change all the other digits around (0 to 1) or (1 to 0) 126 64 32 16 8 4 2 1 0 0 1 1 0 1 0 0 1 1 0 0 1 1 0 0

  16. Alternative Method: Create positive binary number as before: 128 64 32 16 8 4 2 1 0 0 1 1 0 1 0 0 Next change all 1’s and 0’s around: 128 64 32 16 8 4 2 1 1 1 0 0 1 0 1 1 Then add 1 to the number: 128 64 32 16 8 4 2 1 1 1 0 0 1 0 1 1 + 0 0 0 0 0 0 0 1 = 1 1 0 0 1 1 0 0

  17. Addition in Binary 0 1 0 0 1 1 0 1 + 0 0 1 1 1 0 1 1 64 32 16 8 2 1 Denary 128 4 77 59 0 0 0 1 0 0 1 0 1 1 1 1 1 1 136

  18. Addition Exercise • Add 47 to 159 in binary • Add 12 to 47 in binary

  19. Subtraction in Binary • Rather than subtracting, convert the number that is to be subtracted into a negative number then add them together as before

  20. e.g. 15-12 12 = 00001100 -12 = 11110100 15 = 00001111 00001111 + 11110100 (1) 00000011 Subtraction in Binary The carry of 1 is ignored

  21. Subtraction Exercises • Subtract 23 from 123 in binary • Subtract 14 from 32 in binary

  22. Rules: • Positive numbers have a 0 as the MSB • Negative numbers have a 1 as the MSB • Even numbers have 0 as the LSB (Least Significant Bit) • Odd numbers have 1 as the LSB • -1 is always represented by a 1 in every bit regardless of number of bits