Can you convert directly from signed to unsigned? 
Author Message
 Can you convert directly from signed to unsigned?

Quote:

> Hi,
> Does anyone know if there's an easy way to directly convert
> a signed type to an unsigned type, without changing the
> bits? The purpose of this conversion is that I have several
> signed numbers that I want to encode into one long binary
> number.

variable A: SIGNED(7 downto 0);
variable B: UNSIGNED(7 downto 0);
...
B := UNSIGNED(A);

should be what you need. Remember that the SIGNED or UNSIGNED nature
of a bit string is a convention. As long as the types are compatible
(and SIGNED and UNSIGNED are) you can convert one into the other by
using the implicitly declared conversion function that has the same
name as the type (SIGNED to convert any SIGNED compatible type into
a SIGNED object, UNSIGNED to convert any UNSIGNED compatible type
into a UNSIGNED object). Same with STD_ULOGIC_VECTOR and
STD_LOGIC_VECTOR. How to encode your several SIGNED numbers into one
single BIT STRING? Here is an example:

variable A0, A1, A2, A3: SIGNED(7 downto 0);
variable B: UNSIGNED(31 downto 0);
...
B := UNSIGNED(A0 & A1 & A2 & A3);

Hope it helps. Regards,
--
Renaud Pacalet, ENST / COMELEC, 46 rue Barrault 75634 Paris Cedex 13



Sat, 26 Jan 2002 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Convert from Perl to Tcl - Unsigned vs signed problem

2. unsigned word to signed word in RB

3. Signed/Unsigned Documentation CW2.002

4. signed,unsigned in verilog?!

5. Signed/Unsigned Operations for OVI 2.0

6. Signed and unsigned

7. Signed / Unsigned question.

8. Signed and Unsigned numbers?

9. unsigned ,signed how does it works

10. More signed/unsigned arithmetic craziness

11. Numeric STD Signed/Unsigned/Extra

12. signed/unsigned v.s. integer

 

 
Powered by phpBB® Forum Software