Re: two's complement done before storage or on the fly while computing



On Fri, 26 Aug 2005 07:33:09 -0700, Greenhorn wrote:

> Hi,
> yes you are correct that two's complement was used to reduce to the
> costs involved in putting another circuit for performing a subtraction
> operation.

If you have an add instruction then it is about as easy to adapt to to
support subtraction using 1's complement. It is even easier with
sign-magnitude since all you have to do is flip the sign bit of the value
you are subtracting.

The reasons for using 2's complement are different. For example when the
result is represented using the same width as the operands 2's complement
addition and subtraction use the same bit manipulations as unsigned
addition and subtraction, just with different conditions for overflow.
This means that the hardware doesn't have to support different
instructions for signed and unsigned arithmetic.

> I had to switch to the hardware level as the answer by
> 'lawrence' says that today there are machines which do support
> subtraction , i wasn't sure if he meant that with those machines there
> is no need of something like two's complement notation.

Numbers have to be represented in one form or another. Compilers
for machines that support a subtraction instruction will generally use
that instead of some sequence of negation and addition, because it is
likely to be more efficient. OTOH the compiler could generate negation and
addition if it wants to, as long as the code works it doesn't matter as
far as C is concerned.

Lawrence
.



Relevant Pages

  • Re: twos complement done before storage or on the fly while computing
    ... costs involved in putting another circuit for performing a subtraction ... i wasn't sure if he meant that with those machines there ... is no need of something like two's complement notation. ...
    (comp.lang.c)
  • Re: Fighter planes buzz civilian airport; why?
    ... I suspect the error is his, ... subtraction, the smaller subtracted from the larger giving 18, a ... Like with 2s complement inside computers. ... So you would have some runways which were 35 at one end and 1 at the other, ...
    (uk.media.radio.archers)
  • Re: Fighter planes buzz civilian airport; why?
    ... What did I tell husbad wrong that he told ... the arithmetical operation that we need here is subtraction, ... to turning round to face in the opposite direction. ... Like with 2s complement inside computers. ...
    (uk.media.radio.archers)
  • Re: Signed multiplication
    ... in two's complement representation or unsigned, ... "magically" as signed multiplication with two's complement input, ... (size = size of the data types containing it). ... Note that this trick does not work for division, but only for addition, subtraction and multiplication (unless the modulus is prime, which is hardly the case for digital computers... ...
    (comp.dsp)
  • Re: Fighter planes buzz civilian airport; why?
    ... Leverton) wrote: ... the arithmetical operation that we need here is subtraction, ... Like with 2s complement inside computers. ...
    (uk.media.radio.archers)