twos to ones and ones to twos compliments

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

Reply to
chuk
Loading thread data ...

I'd say with XOR and +/-1.

Reply to
Sylvain Munaut

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
 Click to see the full signature
Reply to
rickman

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.

Reply to
Prasanth Kumar

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
 Click to see the full signature
Reply to
rickman

(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

Reply to
glen herrmannsfeldt

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.