# newbie: integer to bit_vector

Discussion in 'VHDL' started by =?ISO-8859-1?Q?Sch=FCle_Daniel?=, May 29, 2006.

1. ### =?ISO-8859-1?Q?Sch=FCle_Daniel?=Guest

Hello,

I want to write a simple test benchmark
I want to generate all possible bit combinations
for bit_vector(7 downto 0) through an integer variable

eg

for i in 0 to 255 loop
bv <= convert(8, i); -- 8 width, and i value
end loop;

is there some convert function for this purpose?

I couldn't find it using google
too much information but not what I am looking for

Regards, Daniel

=?ISO-8859-1?Q?Sch=FCle_Daniel?=, May 29, 2006

2. ### KJGuest

Assuming 'bv' is std_logic_vector(7 downto 0)...

And you include the IEEE numeric_std library...
library IEEE;
use IEEE.numeric_std.all;

then....
for i in 0 to 255 loop
bv <= std_logic_vector(to_unsigned(i, bv'length)); -- 8 width, and i
value
end loop;

KJ

KJ, May 29, 2006

3. ### KJGuest

Oops...just noticed that you wanted 'bv' to be a bit_vector....well, you can
work out that last conversion I'm sure.
KJ

"KJ" <> wrote in message
news:OaKeg.35999\$...
> Assuming 'bv' is std_logic_vector(7 downto 0)...
>
> And you include the IEEE numeric_std library...
> library IEEE;
> use IEEE.numeric_std.all;
>
> then....
> for i in 0 to 255 loop
> bv <= std_logic_vector(to_unsigned(i, bv'length)); -- 8 width, and i
> value
> end loop;
>
> KJ
>

KJ, May 29, 2006
4. ### KJGuest

First nclude the IEEE numeric_std library...
library IEEE;
use IEEE.numeric_std.all;

then....

for i in 0 to 255 loop
bv <= bit_vector(to_unsigned(i, bv'length)); -- 8 width, and i value
end loop;

KJ

KJ, May 29, 2006
5. ### AndyGuest

Use numeric_bit instead of numeric_std package.

It defines signed and unsigned vectors of bit instead of std_logic.

So type conversions from numeric_bit.unsigned to bit are allowed:

bit_vector(unsigned(int_val)) works as long as numeric_bit is used.

Andy
KJ wrote:
> First nclude the IEEE numeric_std library...
> library IEEE;
> use IEEE.numeric_std.all;
>
> then....
>
> for i in 0 to 255 loop
> bv <= bit_vector(to_unsigned(i, bv'length)); -- 8 width, and i value
> end loop;
>
> KJ

Andy, May 30, 2006
6. ### =?ISO-8859-1?Q?Sch=FCle_Daniel?=Guest

thx, it works fine

=?ISO-8859-1?Q?Sch=FCle_Daniel?=, May 30, 2006