1
\$\begingroup\$

We know that to convert unsigned to signed (precisely, I want to convert a pure binary into CA2 number) we must negate the unsigned number adding, then, + 1. In VHDL I can implement an inverter and an adder that manages the carry in. I have two numbers of 32 bits. Is there another way to implement the sum + 1 using anything cheaper? Is there a solution to manage the carry in using only logic gates?

\$\endgroup\$
  • \$\begingroup\$ No, that's for taking the negative of a number. Changing the signedness doesn't involve changing the bit pattern. \$\endgroup\$ – Ignacio Vazquez-Abrams Sep 7 '15 at 21:35
  • \$\begingroup\$ Yeah I know that the pattern is the same, but I need of negative number, I need to see it like a CA2 number \$\endgroup\$ – Anth Sep 7 '15 at 21:37
  • \$\begingroup\$ CA2, CA-2 or CA II may refer to : Carbonic anhydrase II, a human gene California's 2nd congressional district Hummel CA-2, an ultralight aircraft California State Route 2 Ca II, a singly-ionized calcium that produces the H and K lines in the spectrum of many stars \$\endgroup\$ – Bruce Abbott Sep 8 '15 at 0:46
  • \$\begingroup\$ In other words, what (precisely) is a "CA2 number"? It is not a common technical idiom. \$\endgroup\$ – Dave Tweed Sep 8 '15 at 0:59
  • 3
    \$\begingroup\$ CA2 : In French it would be "Complément à 2"="Two's complement". \$\endgroup\$ – TEMLIB Sep 8 '15 at 1:11
4
\$\begingroup\$

It really isn't worth worrying too much about this detail. Adding 1 to a number is such a common idiom in HDL that synthesis tools have highly-evolved methods for dealing wtih it. Also, most modern FPGAs have dedicated, hard-wired fast carry logic that does not consume logic cells, and that synthesis tools know how to take advantage of.

\$\endgroup\$
  • \$\begingroup\$ Thank you for answer. So, do u suggest to implement it in behavioral way and leave everything to synthesizer? \$\endgroup\$ – Anth Sep 8 '15 at 11:15
2
\$\begingroup\$

If it's unsigned, it is by definition positive, therefore it's 2's complement equivalent is also positive, therefore the bit pattern representation is the same.

The one difficulty arises if its MSB is already set : then it is an unsigned too large to represent as a signed number of the same size. So the completely general answer is to sign-extend it into a 2's complement number at least 1 bit wider :

my_signed <= '0' & my_unsigned;

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.