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
twos to ones and ones to twos compliments
Jul 16, 2004
5 Replies
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
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
(snip)
(snip)
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
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required