ece 301 – digital electronics representation of negative numbers, binary arithmetic of...

Click here to load reader

Post on 20-Jan-2016

214 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

  • ECE 301 Digital ElectronicsRepresentation of Negative Numbers,Binary Arithmetic of Negative Numbers,andBinary Codes

    (Lecture #11)The slides included herein were taken from the materials accompanying Fundamentals of Logic Design, 6th Edition, by Roth and Kinney, and were used with permission from Cengage Learning.

  • Spring 2011ECE 301 - Digital Electronics*

    Representation of Negative Numbers

    (continued)

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*Signed Binary NumbersRepresentations for signed binary numbers:

    1. Sign and Magnitude2. 1's Complement3. 2's Complement

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*Signed Binary NumbersArithmetic circuits are difficult to design for Sign and Magnitude binary numbers.Consequently, this number system is not typically used in digital (computer) systems.Instead other number systems, namely the 1's and 2's Complements, are more commonly used.As we will see, it is rather easy to design arithmetic circuits for binary numbers represented in these number systems.

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*1's ComplementA positive number, N, is represented in the same way as in the Sign and Magnitude representation.For an n-bit number,The leftmost bit (sign bit) = 0.Indicating a positive number.The remaining n-1 bits represent the magnitude.

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*1's ComplementA negative number, -N, is represented by the 1's complement of the positive number, N.N' = 1's complement representation for -N.For an n-bit signed binary number,

    The leftmost bit (sign bit) = 1 for all negative numbers in the 1's Complement system.N' = (2n 1) N

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*1's Complement: ExamplesUsing 8 bits, determine the 1's Complement representation for the following negative numbers:

    -15-102

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*1's ComplementThe 1's Complement representation for -N can also be determined by taking the bit-wise complement of N.N' = 1's Complement representation for -N.For an n-bit signed binary number,

    i.e. complement N, bit-by-bitN' = bit-wise complement of N

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*1's Complement: ExamplesUsing 8 bits, determine the 1's Complement representation for the following negative numbers:

    -15-102(Use the bit-wise complement)

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*1's ComplementFor an n-bit 1's Complement binary number,

    Includes a representation for +0 and -0.Represents an equal number of positive and negative values.- (2n-1 1)

  • Spring 2011ECE 301 - Digital Electronics*1's ComplementTo determine the magnitude of a negative number, -N, that is represented by its 1's Complement, N', simply take the 1's complement of the 1's Complement.N = (2n 1) N'N = bit-wise complement of N'orpositive #1's complement rep.for negative #

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*2's ComplementA positive number, N, is represented in the same way as in the Sign and Magnitude representation.For an n-bit number,The leftmost bit (sign bit) = 0.Indicating a positive number.The remaining n-1 bits represent the magnitude.

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*2's ComplementA negative number, -N, is represented by the 2's complement of the positive number, N.N* = 2's complement representation for -N.For an n-bit signed binary number,

    The leftmost bit (sign bit) = 1 for all negative numbers in the 2's Complement system.N* = (2n) N

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*2's Complement: ExamplesUsing 8 bits, determine the 2's Complement representation for the following negative numbers:

    -12-95

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*2's ComplementThe 1's and 2's Complement representations for a negative number, -N, are related as follows:

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*2's ComplementThus, the 2's Complement representation for -N can also be determined by adding 1 to the 1's Complement representation for -N.N' = 1's Complement representation for -N.N* = 2's Complement representation for -N.For an n-bit signed binary number,N* = N' + 1

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*2's Complement: ExamplesUsing 8 bits, determine the 2's Complement representation for the following negative numbers:

    -12-95(Use the 1's complement)

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*2's ComplementFor an n-bit 2's Complement binary number,

    Includes only one representation for 0.Represents an additional negative value.- (2n-1)

  • Spring 2011ECE 301 - Digital Electronics*2's ComplementTo determine the magnitude of a negative number, -N, that is represented by its 2's Complement, N*, simply take the 2's complement of the 2's Complement.N = (2n) N*N = (N*)' + 1orpositive #2's complement rep. for negative #bit-wise complement of 2's complement

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*Signed Binary Numbers

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*Binary ArithmeticofSigned Binary Numbers

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*2's Complement AdditionAddition of n-bit signed binary numbers is straightforward using the 2's Complement number system.Addition is carried out in the same way as for n-bit positive numbers.Carry from the sign bit (leftmost bit) is ignored.Overflow occurs if the correct result (including the sign bit) cannot be represented in n bits.

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*2's Complement Addition: ExampleUsing 2's Complement addition and 8-bit representation, add the following numbers:

    -47 + 83 Did overflow occur?

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*2's Complement Addition: ExampleUsing 2's Complement addition and 8-bit representation, add the following numbers:

    -32 + -105 Did overflow occur?

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*2's Complement Addition: ExampleUsing 2's Complement addition and 8-bit representation, add the following numbers:

    19 + 52 Did overflow occur?

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*2's Complement Addition: ExampleUsing 2's Complement addition and 8-bit representation, add the following numbers:

    64 + 78 Did overflow occur?

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*2's Complement SubtractionSubtraction can be implemented using addition.

    Determine the 2's Complement representation for the negative number -B.Use 2's Complement addition to add A and -B.A B = A + (-B)

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*2's Complement Subtraction: Example Subtract the following numbers, using 2's Complement addition and 8-bit representation:

    64 78 Did overflow occur?

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*2's Complement Subtraction: Example Subtract the following numbers, using 2's Complement addition and 8-bit representation:

    -35 62 Did overflow occur?

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*2's Complement Subtraction: Example Subtract the following numbers, using 2's Complement addition and 8-bit representation:

    14 (-59) Did overflow occur?

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*2's Complement Subtraction: Example Subtract the following numbers, using binary subtraction and 8-bit representation:

    27 45 Can this subtraction be carried out?

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*1's Complement AdditionSimilar to 2's Complement Addition of n-bit signed binary numbers.However, rather than ignore the carry-out from the sign (leftmost) bit, add it to the least significant bit (LSB) of the n-bit sum.Known as the end-around carry.

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*1's Complement Addition: ExampleUsing 1's Complement addition and 8-bit representation, add the following numbers:

    -31 + -84 Did overflow occur?

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*1's Complement Addition: ExampleUsing 1's Complement addition and 8-bit representation, add the following numbers:

    52 + 73 Did overflow occur?

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*OverflowThe general rule for detecting overflow when performing 2's Complement or 1's Complement Addition:An overflow occurs when the addition of two positive numbers results in a negative number.An overflow occurs when the addition of two negative numbers results in a positive number.Overflow cannot occur when adding a positive number to a negative number.

    ECE 301 - Digital Electronics

  • Spring 2011ECE 301 - Digital Electronics*Binary Codes

    ECE 301 - Digital Elec

View more