DRO-Lesson 09 - Negative Numbers Representation Part 3fchs

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 26

HNDIT1104: Data Representation and Organization

Negative numbers
representation
Part - 3

Lesson 9
Learning Objectives
• At the end of the lesson student should be
able to
– Convert decimal number into 8 bits 2’s
complement representation
– Convert number in 2’s complement format to
decimal
Two’s Complement Representation

To compute negative values using Two’s


Complement representation:

1) Begin with the binary representation of the


positive value
2) Complement (flip each bit -- if it is 0 make it
1 and visa versa) the entire positive
number
3) Then add one.
Two’s Complement Representation

Ex 1. Find the 8-bit two’s complement


representation of –610

Step 1: Find binary representation of the


positive value in 8 bits
610 = 000001102
Two’s Complement Representation
Ex 1:

Step 2: Complement the entire positive value

Positive Value: 00000110


Complemented: 11111001
Two’s Complement Representation
Ex 1:

Step 3: Add one to complemented value


 
(complemented) -> 11111001
(add one) -> + 1
11111010
So: -610 = 111110102
(in 8-bit 2's complement form)
Two’s Complement Representation
Ex 2. Find the 8-bit two’s complement
representation of 2010

Step 1: Find binary representation of the positive


value in 8 bits
2010 = 000101002

20 is positive, so STOP after step 1!


So: 2010 = 000101002
(in 8-bit 2's complement form)
Two’s Complement Representation

Ex 3. Find the 8-bit two’s complement


representation of –8010

Step 1: Find binary representation of the


positive value in 8 bits
8010 = 010100002

-80 is negative, so continue…


Two’s Complement Representation

Ex 3

Step 2: Complement the entire positive


value

Positive Value: 01010000

Complemented: 10101111
Two’s Complement Representation
Ex 3

Step 3: Add one to complemented value


 
(complemented) ->10101111
(add one) ->+ 1
10110000

So: -8010 = 101100002


(in 8-bit 2's complement form)
Two’s Complement Representation
Alternate method -- replaces previous steps 2-3 

Step 2: Scanning the positive binary representation


from right to left,
find first one bit, from low-order (right) end

Step 3: Complement (flip) the remaining bits to the


left.
  00000110
(left complemented) --> 11111010
Two’s Complement Representation

Ex 1: Find the Two’s Complement of -7610


 
Step 1: Find the 8-bit binary representation of
the positive value.
 
7610 = 010011002
 
Two’s Complement Representation

Step 2-3: Find first one(1) bit, from low-order (right)


end,
and complement the pattern to the left.
  01001100
(left complemented) -> 10110100
  

So: -7610 = 101101002


(in 8-bit 2's complement form) 
Ex 2: Find the Two’s Complement of 7210

Step 1: Find the 8 bit binary representation of


the positive value.
  7210 = 010010002

Steps 2-3: 72 is positive, so STOP after step 1!


So: 7210 = 010010002
(in 8-bit 2's complement form)
Ex 3: Find the Two’s Complement of -2610

 
  
So: -2610 = 111001102
(in 8-bit 2's complement form) 
Two’s Complement Representation

32-bit example:
+9
0 000 0000 0000 0000 0000 0000 0000 1001
-9
1 111 1111 1111 1111 1111 1111 1111 0111

Sign bit: 31 remaining bits for


0 --> positive magnitude
1 --> negative (i.e. value stored in two’s
complement form)
Two’s Complement to Decimal

Ex 1: Find the decimal equivalent of the 8-bit 2’s


complement value 111011002

 
Step 1: Determine if number is positive or
negative:

11101100 2

Leftmost bit is 1, so number is negative.


Two’s Complement to Decimal

Ex 1:

Step 2: Find first one bit, from low-order (right)


end, and complement the pattern to the
left.
11101100
(left complemented) 00010100
Two’s Complement to Decimal
Ex 1:

Step 3: Determine the numeric value:


000101002 = 16 + 4 = 2010

So: 111011002 = -2010 (8-bit 2's


complement form) 
Two’s Complement to Decimal
Ex 2: Find the decimal equivalent of the 8-bit
2’s complement value 010010002
 

Step 1: Determine if number is positive or negative:

Leftmost bit is 0, so number is positive.


Skip to step 3.
Two’s Complement to Decimal

Ex 2

Step 3: Determine the numeric value:


010010002 = 64 + 8 = 7210

So: 010010002 = 7210


(8-bit 2's complement form) 
Two’s Complement to Decimal
Ex 3: Find the decimal equivalent of the8-bit 2’s
complement value 110010002
 

Step 1: Determine if number is positive or


negative:

Leftmost bit is 1, so number is negative.


Two’s Complement to Decimal

Ex 3:

Step 2: Find first one bit, from low-order (right) end,


and complement the pattern to the left.
  11001000
(left complemented) 00111000
Two’s Complement to Decimal

Ex 3:

Step 3: Determine the numeric value


001110002 = 32 + 16 + 8 = 5610

So: 110010002 = -5610 (8-bit


2's complement form) 
Two’s Complement Representation

Summary - Benefits of Twos Complements:


• Addition and subtraction are simplified in the
two’s-complement system,
• -0 has been eliminated, replaced by one
extra negative value, for which there is no
corresponding positive number.

You might also like