Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   VHDL (http://www.velocityreviews.com/forums/f18-vhdl.html)
-   -   Converting logic_vector -> natural (http://www.velocityreviews.com/forums/t23778-converting-logic_vector-natural.html)

 magik 06-26-2005 10:57 AM

Converting logic_vector -> natural

Hi

I want to convert vect(3 downto 0) into natural digit

is there any standard conversion procedure/function in vhdl for that??

Paul

 David Bishop 06-26-2005 01:04 PM

Re: Converting logic_vector -> natural

magik wrote:

> Hi
>
> I want to convert vect(3 downto 0) into natural digit
>
> is there any standard conversion procedure/function in vhdl for that??

use ieee.numeric_std.all;

.....
variable natvar : natural;
variable vect : std_logic_vector (3 downto 0);
......

natvar := to_integer(unsigned(vect));

 magik 06-26-2005 01:12 PM

Re: Converting logic_vector -> natural

thanx!!

I used conv_integer from std_logic_unsigned and the result is the same :)

Uzytkownik "David Bishop" <dbishop@vhdl.org> napisal w wiadomosci
news:HJxve.54606\$g5.22335@twister.nyroc.rr.com...
> magik wrote:
>
>> Hi
>>
>> I want to convert vect(3 downto 0) into natural digit
>>
>> is there any standard conversion procedure/function in vhdl for that??

>
> use ieee.numeric_std.all;
>
> ....
> variable natvar : natural;
> variable vect : std_logic_vector (3 downto 0);
> .....
>
> natvar := to_integer(unsigned(vect));
>

 Ralf Hildebrandt 06-26-2005 05:20 PM

Re: Converting logic_vector -> natural

magik wrote:

> I used conv_integer from std_logic_unsigned and the result is the same :)

Don't do it. First this library is /not/ a standard library. Your code is not protable.
Second you always assume /unsigned/ numbers in the vector. It is much better to treat
std_(u)logic_vectors neighter as signed nor as unsigned number in general and to choose it
using the conversion unsigned() or signed() dependend on the context.

O.k. - for your conversion to natural, which cover non-negative integers there is no
problem, but a conversion to integer would never lead to negative numbers.

Ralf

 kunal.bandekar 05-24-2011 09:25 AM

Logic_vector to Natural

--CONSTANT declaration
constant COUNTER_LOGIC : integer := 8;

signal count : std_logic_vector (COUNTER_LOGIC-1 downto 0);

-- Felt it very useful if you want to avoid writing code multiple times and then thinking of scaling logic in the long run
start_of_frameopti_reg(conv_integer(count)) <= '1';
start_of_frameopti_reg((conv_integer(count))-1) <= '0';

 All times are GMT. The time now is 11:26 AM.