twos to ones and ones to twos compliments

C

chuk

Guest
Any one know of the most efficient method (seed and space wise) of
implementing conversion of ones to twos and twos to ones compliment???
Currently using addition and subtraction, but this is very
waist-full!!!
thanks
C
 
chuk wrote:
Any one know of the most efficient method (seed and space wise) of
implementing conversion of ones to twos and twos to ones compliment???
Currently using addition and subtraction, but this is very
waist-full!!!
thanks
C
I'd say with XOR and +/-1.
 
Sylvain Munaut wrote:
chuk wrote:
Any one know of the most efficient method (seed and space wise) of
implementing conversion of ones to twos and twos to ones compliment???
Currently using addition and subtraction, but this is very
waist-full!!!
thanks
C
I'd say with XOR and +/-1.
By definition, converting between 2's comp and 1's comp is a matter of
adding or subtracting 1. If you use XOR you still need a carry and you
are just building your own half adder.

Perhaps there is a different way to solve the larger problem? Can Chuk
tell us why he is converting between 2's and 1's complement? Maybe we
can find a way to combine this operation with something else or maybe it
is not needed at all?

So where is the data coming from and what are you trying to do with the
converted number?

--

Rick "rickman" Collins

rick.collins@XYarius.com
Ignore the reply address. To email me use the above address with the XY
removed.

Arius - A Signal Processing Solutions Company
Specializing in DSP and FPGA design URL http://www.arius.com
4 King Ave 301-682-7772 Voice
Frederick, MD 21701-3110 301-682-7666 FAX
 
On Fri, 2004-07-16 at 12:03 +0200, Sylvain Munaut wrote:
chuk wrote:
Any one know of the most efficient method (seed and space wise) of
implementing conversion of ones to twos and twos to ones compliment???
Currently using addition and subtraction, but this is very
waist-full!!!
thanks
C
I'd say with XOR and +/-1.
The shortcut from doing 2's compliment is to invert the bits after the
first 1 starting from the right. So for example:

10011100 (original value)
VVVVV^The first 1 from the right
01100100 (2's compliment)

Thus you can create an chain of 'or' gates connected to 'xor' gates to
invert the bits after the first 1 bit starting from the right. It is
possible to do this work in parallel but without implementing it, I
don't know if it will actually be faster than a straightforward addition
since most FPGAs have fast ripple-carry adders.
 
Prasanth Kumar wrote:
On Fri, 2004-07-16 at 12:03 +0200, Sylvain Munaut wrote:
chuk wrote:
Any one know of the most efficient method (seed and space wise) of
implementing conversion of ones to twos and twos to ones compliment???
Currently using addition and subtraction, but this is very
waist-full!!!
thanks
C
I'd say with XOR and +/-1.

The shortcut from doing 2's compliment is to invert the bits after the
first 1 starting from the right. So for example:

10011100 (original value)
VVVVV^The first 1 from the right
01100100 (2's compliment)

Thus you can create an chain of 'or' gates connected to 'xor' gates to
invert the bits after the first 1 bit starting from the right. It is
possible to do this work in parallel but without implementing it, I
don't know if it will actually be faster than a straightforward addition
since most FPGAs have fast ripple-carry adders.
I don't think this method is really a short cut other than if you are
doing it using paper and pencil. This is the same calculation that the
inverters and adder does.

The OP is really just trying to find a way to not have to do the
addition, but in reality there is no way around it.

--

Rick "rickman" Collins

rick.collins@XYarius.com
Ignore the reply address. To email me use the above address with the XY
removed.

Arius - A Signal Processing Solutions Company
Specializing in DSP and FPGA design URL http://www.arius.com
4 King Ave 301-682-7772 Voice
Frederick, MD 21701-3110 301-682-7666 FAX
 
rickman wrote:

(snip)

chuk wrote:

Any one know of the most efficient method (seed and space wise) of
implementing conversion of ones to twos and twos to ones compliment???
(snip)

I don't think this method is really a short cut other than if you are
doing it using paper and pencil. This is the same calculation that the
inverters and adder does.

The OP is really just trying to find a way to not have to do the
addition, but in reality there is no way around it.
Note that while in many ways twos complement seems simpler
than ones complement this example shows a case where it isn't.

There are some advantages to ones complement, though not quite
as many.

-- glen
 

Welcome to EDABoard.com

Sponsor

Back
Top