std_logic_vector to unsigned/signed conversion

OP (Company: REASON) #3008805
Hi, I have some doubts about the use of the conversions from 
std_logic_vector to signed/unsigned. I always use the conversion 
signed(...), unsigned(...), but when I try to use the conversions 
defined by the library (to_signed, to_unsigned), it doesn't work. Can 
someone explain to me why this happens? And why the conversion 
unsigned() and signed() works?

Thank you.
OP (Company: REASON) #3008860
Sorry, I think I wasn't clear enough. I'm using numeric_std to convert 
std_logic_vector to unsigned.  For example: When I use "to_unsigned()" 
it doesn't work. But "unsigned()" works.

Thank you
Moderator (Company: Titel) #3008893
> For example: When I use "to_unsigned()" it doesn't work.
> But "unsigned()" works.
Of course: these are different functions with different operands. The 
to_unsigned() expects an integer as first operand and a vector length as 
second operand. Then it converts the integer to a unsigned vector of the 
desired length.
The unsigned() cast converts nothing, it just takes the std_logic vector 
and interprets it as an unsigned vector.

Try this:
http://www.lothar-miller.de/s9y/categories/16-Numeric_Std
Its German. But a picture says more than 1000 words...   ;-)
Moderator (Company: Titel) #3012175
See the definition of those types:
1
  type UNSIGNED is array (NATURAL range <>) of STD_LOGIC;
2
  type SIGNED is array (NATURAL range <>) of STD_LOGIC;
  (from numeric_std)
And the one for this here:
1
  TYPE std_logic_vector IS ARRAY ( NATURAL RANGE <>) OF std_logic;
  (from Std_Logic_1164)

Then you will see, that the cast only tells the synthesizer to look at 
the very same bits in another way.

This also works the other way:
If you write "110001110001" then you don't know whether its signed, 
unsigned or a std_logic_vector (it also could be a bit_vector or 
somethin else). Then you must tell the synthesizer what you mean. This 
is done with a qualifier
http://www.lothar-miller.de/s9y/archives/82-Qualifier.html

Reply

A question of your own? This thread is over 13 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.