Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > 2's complement vs. 1's complement vs. ...

Reply
Thread Tools

2's complement vs. 1's complement vs. ...

 
 
Roberto Waltman
Guest
Posts: n/a
 
      06-09-2011
Peter Nilsson wrote:
> Keith Thompson wrote:


>> A 2's-complement representation makes some operations easier,


>And some harder.


Could you expand this? What operations are easier using other
representations? (Other than BCD, etc. for financial applications.)
--
Roberto Waltman

[ Please reply to the group.
Return address is invalid ]
 
Reply With Quote
 
 
 
 
Ben Pfaff
Guest
Posts: n/a
 
      06-09-2011
Roberto Waltman <(E-Mail Removed)> writes:

> Peter Nilsson wrote:
>> Keith Thompson wrote:

>
>>> A 2's-complement representation makes some operations easier,

>
>>And some harder.

>
> Could you expand this? What operations are easier using other
> representations? (Other than BCD, etc. for financial applications.)


I suspect (without looking it up) that multiplication and
division with negative numbers is harder in two's complement than
in sign-magnitude.
--
"Programmers have the right to be ignorant of many details of your code
and still make reasonable changes."
--Kernighan and Plauger, _Software Tools_
 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      06-09-2011
Roberto Waltman <(E-Mail Removed)> writes:
>> Keith Thompson wrote:
>>> A 2's-complement representation makes some operations easier,

>
>>And some harder.

>
> Could you expand this? What operations are easier using other
> representations? (Other than BCD, etc. for financial applications.)


The most obvious example is negation. In sign and magnitude, you
just invert the sign bit. In ones' complement, you invert every bit.
In two's complement, you invert every bit and then increment (which
can toggle every bit again).

This assumes that he difficulty of an operation is measured by the
number of bits that are affected, which probably isn't the case.

(Note the correct placement of the apostrophes: "two's complement"
and "ones' complement".)

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Joe Pfeiffer
Guest
Posts: n/a
 
      06-09-2011
Keith Thompson <(E-Mail Removed)> writes:

> Roberto Waltman <(E-Mail Removed)> writes:
>>> Keith Thompson wrote:
>>>> A 2's-complement representation makes some operations easier,

>>
>>>And some harder.

>>
>> Could you expand this? What operations are easier using other
>> representations? (Other than BCD, etc. for financial applications.)

>
> The most obvious example is negation. In sign and magnitude, you
> just invert the sign bit. In ones' complement, you invert every bit.
> In two's complement, you invert every bit and then increment (which
> can toggle every bit again).


A 2's complement carry-lookahead adder takes half the carry logic of a
1's complement (because the 1's complement has a wrap-around carry).

A sign-magnitude adder is a mess, since you have to compare the signs on
the inputs to decide whether you're going to add vs. subtract, and
compare magnitudes to decide which one you subtract from the other.

By the time you've got the hardware on hand to both add and subtract,
being able to invert a number doesn't take any new hardware to speak of.

> This assumes that he difficulty of an operation is measured by the
> number of bits that are affected, which probably isn't the case.

 
Reply With Quote
 
Michael Press
Guest
Posts: n/a
 
      06-13-2011
In article <(E-Mail Removed)>,
Roberto Waltman <(E-Mail Removed)> wrote:

> Peter Nilsson wrote:
> > Keith Thompson wrote:

>
> >> A 2's-complement representation makes some operations easier,

>
> >And some harder.

>
> Could you expand this? What operations are easier using other
> representations? (Other than BCD, etc. for financial applications.)


Bignum packages. Here, you answer your own question.
Design routines to add two bignums.
One for signed-magnitude representation,
one for 2's complement representation.

--
Michael Press
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VHDL code for 2's complement nick VHDL 3 09-12-2012 12:05 PM
1's complement and 2's complement sarathy C++ 22 08-02-2006 05:53 PM
1's complement and 2's complement sarathy C Programming 20 08-02-2006 05:53 PM
sign magnitude, ones complement, two's complement Mantorok Redgormor C Programming 8 10-07-2003 11:52 PM
Conversion 1QN -> 2'Complement Troels Smit VHDL 1 07-01-2003 09:43 AM



Advertisments