Two's complement: Difference between revisions

From Citizendium
Jump to navigation Jump to search
imported>Stephen Ewen
({{subpages}})
imported>Chris Day
No edit summary
Line 5: Line 5:


Addition and subtraction of two's complement numbers is easy.  Since subtraction is essentially the addition of a negative (which is to say that A - B = A + (-B)), reversing the one of the numbers and adding them creates subtraction.  To do this in hardware, one uses a control bit (A), which is 0 for addition and 1 for subtraction.  This control bit is [[XOR]]ed with each Y input, and serves as the carry-in for the least significant bit.  When A=0, the adder functions normally.  When A=1, each digit in Y is reversed and 1 is added to it.
Addition and subtraction of two's complement numbers is easy.  Since subtraction is essentially the addition of a negative (which is to say that A - B = A + (-B)), reversing the one of the numbers and adding them creates subtraction.  To do this in hardware, one uses a control bit (A), which is 0 for addition and 1 for subtraction.  This control bit is [[XOR]]ed with each Y input, and serves as the carry-in for the least significant bit.  When A=0, the adder functions normally.  When A=1, each digit in Y is reversed and 1 is added to it.
{{BASEPAGENAME}}

Revision as of 15:46, 19 March 2008

This article is developing and not approved.
Main Article
Discussion
Definition [?]
Related Articles  [?]
Bibliography  [?]
External Links  [?]
Citable Version  [?]
 
This editable Main Article is under development and subject to a disclaimer.

Two's complement is a signed binary numbering system. It is one commonly used in low-level hardware implementations, due to the ease of designing adders and subtracters for it. While sometimes harder for people to understand and work with, it's easier for computers to use than one's complement.

To convert an unsigned binary number into its two's complement negative, one first toggles each of the digits, and then adds one. Positive two's complement numbers are identical to their unsigned equivalents, except that the first digit is a zero. Whereas an unsigned binary number with N digits has a range from 0 to (2^N)-1, a two's complement number spans - 2^(N-1) through 2^(N-1) -1.

Addition and subtraction of two's complement numbers is easy. Since subtraction is essentially the addition of a negative (which is to say that A - B = A + (-B)), reversing the one of the numbers and adding them creates subtraction. To do this in hardware, one uses a control bit (A), which is 0 for addition and 1 for subtraction. This control bit is XORed with each Y input, and serves as the carry-in for the least significant bit. When A=0, the adder functions normally. When A=1, each digit in Y is reversed and 1 is added to it.


Two's complement