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

Reply

VHDL - Converting integer to std_logic_vector

 
Thread Tools Search this Thread
Old 12-06-2007, 04:05 AM   #1
Default Converting integer to std_logic_vector


Hi,

I am new to VHDL. I want to convert an integer to std_logic_vector of
length 32. Is there any in-built function in VHDL for this?

I am doing the following includes:

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

Thanks,
Abhishek


Rockerboy
  Reply With Quote
Old 12-06-2007, 04:19 AM   #2
Rockerboy
 
Posts: n/a
Default Re: Converting integer to std_logic_vector
Moments after I posted, I found conv_std_logic_vector is the right
function

On Dec 5, 9:05 pm, Rockerboy <rka...@gmail.com> wrote:
> Hi,
>
> I am new to VHDL. I want to convert an integer to std_logic_vector of
> length 32. Is there any in-built function in VHDL for this?
>
> I am doing the following includes:
>
> library ieee;
> use ieee.std_logic_1164.all;
> use ieee.std_logic_arith.all;
> use ieee.std_logic_unsigned.all;
>
> Thanks,
> Abhishek




Rockerboy
  Reply With Quote
Old 12-06-2007, 04:37 AM   #3
KJ
 
Posts: n/a
Default Re: Converting integer to std_logic_vector

"Rockerboy" <> wrote in message
news:8ddd4fbb-46f8-4fe2-a067-...
> Moments after I posted, I found conv_std_logic_vector is the right
> function
>

Actually you shouldn't use std_logic_arith. It's not an IEEE standard, it's
just something that an early VHDL supplier came up with...it has some
issues.

What you should use instead is ieee.numeric_std. In that package are
to_unsigned() and to_signed() functions that convert integers into the
appropriate representations. unsigned and signed can then be simply
converted to std_logic_vector.

Usage example:
use ieee.numeric_std.all;
.....
my_slv <= std_logic_vector(to_unsigned(my_integer, my_slv'length)); -- if
my_integer is actually 'natural'
my_slv <= std_logic_vector(to_signed(my_integer, my_slv'length)); -- if
my_integer could be negative

KJ




KJ
  Reply With Quote
Old 12-07-2007, 06:51 PM   #4
tigerx
 
Posts: n/a
Default Re: Converting integer to std_logic_vector
Hi Abhishek,

there is an inbuilt function in VHDL to convert interger to
logic_vector.

In declaration do like this.

signal temp_integer: integer;
signal temp: std_logic_vector(31 downto 0);

Here how you can convert

temp <= conv_std_logic_vector(temp_integer,32);


Enjoy!!!


On Dec 6, 9:05 am, Rockerboy <rka...@gmail.com> wrote:
> Hi,
>
> I am new to VHDL. I want to convert an integer to std_logic_vector of
> length 32. Is there any in-built function in VHDL for this?
>
> I am doing the following includes:
>
> library ieee;
> use ieee.std_logic_1164.all;
> use ieee.std_logic_arith.all;
> use ieee.std_logic_unsigned.all;
>
> Thanks,
> Abhishek




tigerx
  Reply With Quote
Old 12-07-2007, 07:19 PM   #5
Dave
 
Posts: n/a
Default Re: Converting integer to std_logic_vector
On Dec 7, 1:51 pm, tigerx <mp.techpa...@googlemail.com> wrote:
> Hi Abhishek,
>
> there is an inbuilt function in VHDL to convert interger to
> logic_vector.
>
> In declaration do like this.
>
> signal temp_integer: integer;
> signal temp: std_logic_vector(31 downto 0);
>
> Here how you can convert
>
> temp <= conv_std_logic_vector(temp_integer,32);
>
> Enjoy!!!
>
> On Dec 6, 9:05 am, Rockerboy <rka...@gmail.com> wrote:
>
>
>
> > Hi,

>
> > I am new to VHDL. I want to convert an integer to std_logic_vector of
> > length 32. Is there any in-built function in VHDL for this?

>
> > I am doing the following includes:

>
> > library ieee;
> > use ieee.std_logic_1164.all;
> > use ieee.std_logic_arith.all;
> > use ieee.std_logic_unsigned.all;

>
> > Thanks,
> > Abhishek- Hide quoted text -

>
> - Show quoted text -


No, really, use to_unsigned from numeric_std, and cast to
std_logic_vector like KJ says. It is the IEEE standard library for
signed and unsigned types. Especially when you're learning the
language, you want to learn to do things the right way, and build good
coding habits.

Changing the world, one engineering student at a time...


Dave
  Reply With Quote
Old 12-10-2007, 07:59 PM   #6
Andy
 
Posts: n/a
Default Re: Converting integer to std_logic_vector
On Dec 7, 12:51 pm, tigerx <mp.techpa...@googlemail.com> wrote:
> Hi Abhishek,
>
> there is an inbuilt function in VHDL to convert interger to
> logic_vector.
>
> In declaration do like this.
>
> signal temp_integer: integer;
> signal temp: std_logic_vector(31 downto 0);
>
> Here how you can convert
>
> temp <= conv_std_logic_vector(temp_integer,32);
>
> Enjoy!!!
>
> On Dec 6, 9:05 am, Rockerboy <rka...@gmail.com> wrote:
>
> > Hi,

>
> > I am new to VHDL. I want to convert an integer to std_logic_vector of
> > length 32. Is there any in-built function in VHDL for this?

>
> > I am doing the following includes:

>
> > library ieee;
> > use ieee.std_logic_1164.all;
> > use ieee.std_logic_arith.all;
> > use ieee.std_logic_unsigned.all;

>
> > Thanks,
> > Abhishek


The conv_std_logic() function is not "inbuilt" in vhdl. It is a
function in a package that, while residing in the IEEE library in most
tools, is not an official part of the language standard or any IEEE
standard package. It was put there, in violation of the IEEE standard,
by synopsys, and everyone else has followed suit, to maintain
compatibility with synopsys.

The IEEE standard way to use arithmetic with vectors is to cast them
to numeric_std.signed or numeric_std.unsigned, as appropriate for the
values you are trying to use. The IEEE standard numeric_std package
includes conversions to and from signed/unsigned and integer.

Andy



Andy
  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
How to convert string contain Hex data into integer asifjavaid Software 0 09-09-2008 08:50 AM
Converting PAL DVDs to NTSC DVDs. Wild Coyote DVD Video 14 10-27-2004 09:58 PM
HELP ! - problem converting "windows movie maker" to "click to dvd" Terry Hoknes DVD Video 0 07-23-2004 06:17 AM
HD-DVD and DVD's future Phil Riker DVD Video 68 09-28-2003 09:32 PM
Converting my PAL & NTSC videos & Hi8 CamCorder tapes to DVD Joe Smith DVD Video 8 09-08-2003 03:36 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