Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - Converting logic_vector -> natural

 
Thread Tools Search this Thread
Old 06-26-2005, 11:57 AM   #1
Default 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





magik
  Reply With Quote
Old 06-26-2005, 02:04 PM   #2
David Bishop
 
Posts: n/a
Default 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));



David Bishop
  Reply With Quote
Old 06-26-2005, 02:12 PM   #3
magik
 
Posts: n/a
Default Re: Converting logic_vector -> natural
thanx!!

I used conv_integer from std_logic_unsigned and the result is the same


Uzytkownik "David Bishop" <> napisal w wiadomosci
news:HJxve.54606$...
> 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
  Reply With Quote
Old 06-26-2005, 06:20 PM   #4
Ralf Hildebrandt
 
Posts: n/a
Default 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


Ralf Hildebrandt
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help - Method for converting float to double mcvishnuprasad The Lounge 2 07-24-2008 02:00 PM
Problems converting avi to DVD using WinAVI Help!! KIMOSABE DVD Video 4 01-04-2007 08:58 PM
DVD Verdict reviews: NATURAL CITY, UNO BIANCA, GODZILLA: MONSTER EDITION, and more! DVD Verdict DVD Video 0 04-27-2006 09:21 AM
Converting HD to Divx or Wmv HD how ??? No One Realy DVD Video 0 09-13-2005 06:22 PM
HD-DVD and DVD's future Phil Riker DVD Video 68 09-28-2003 09:32 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46