Twos Complement Twos Complement n A system used

  • Slides: 22
Download presentation
Two’s Complement

Two’s Complement

Two’s Complement n A system used to represent a negative number in binary Positive

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

On a cars Mileometer if you went backwards this would happen: 9 0 9

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

Two’s Complement is like a Speedometer……. 128 64 32 16 8 0 0 Positive

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

Two’s Complement is like a Speedometer……. 128 64 32 16 8 0 0 0

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

Two’s Complement is like a Speedometer……. 128 64 32 16 8 0 0 0

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

Two’s Complement is like a Speedometer……. 128 64 32 16 8 0 0 0

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

Two’s Complement is like a Speedometer……. -128 64 32 16 8 1 1 1

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

Two’s Complement is like a Speedometer……. -128 64 32 16 8 1 1 1

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

Two’s Complement is like a Speedometer……. -128 64 32 16 8 1 1 1

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

How can you convert a negative two’s complement number to denary? Example: Convert two’s

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

Example 2 Convert two’s complement 11011011 -128 1 64 1 32 16 0 1

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

Activity Convert the following numbers to denary: 1. 2. 3. 4. Two’s complement 0011

Activity Convert the following numbers to denary: 1. 2. 3. 4. Two’s complement 0011 Two’s complement 1100 Two’s complement 10111101 Binary (no +- MSB at the start) 11110101

How can you convert a negative denary number into two’s complement? Step 1 pretend

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 0 64 0 32 16 1 1 8 4 0 1 2 0 1 0

How can you convert a negative denary number into two’s complement? Step 2 Starting

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 0

Alternative Method: Create positive binary number as before: 128 64 32 16 8 0

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

Addition in Binary 128 64 32 16 8 4 2 1 0 0 1

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

Addition Exercise Add 47 to 159 in binary n Add 12 to 47 in

Addition Exercise Add 47 to 159 in binary n Add 12 to 47 in binary n

Subtraction in Binary n Rather than subtracting, convert the number that is to be

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

Subtraction in Binary e. g. 15 -12 12 = 00001100 -12 = 11110100 15

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

Subtraction Exercises 1. 2. Subtract 23 from 123 in binary Subtract 14 from 32

Subtraction Exercises 1. 2. Subtract 23 from 123 in binary Subtract 14 from 32 in binary

Rules: Positive numbers have a 0 as the MSB n Negative numbers have a

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