determine slv width by given integer range

O

Olaf

Hi,

maybe I did not seek the c.l.vhdl FAQ very carefully, but I did not
found a way to determine the bit width of a std_logic_vector/unsigned by
a given integer range. What I want to do is like this:

subtype level_t is integer range 0 to 8; -- width 3 downto 0
signal level : unsigned(?? downto ??); -- can hold level_t range

Is there a way?

Thanks
Olaf
 
N

Nicolas Matringe

Olaf a écrit :
Hi,

maybe I did not seek the c.l.vhdl FAQ very carefully, but I did not
found a way to determine the bit width of a std_logic_vector/unsigned by
a given integer range. What I want to do is like this:

subtype level_t is integer range 0 to 8; -- width 3 downto 0
signal level : unsigned(?? downto ??); -- can hold level_t range

Is there a way?

You need a log2 function (search for it, there are a few available) :

signal level : unsigned(log2(level_t'high) downto 0);

Nicolas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top