Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

VHDL to_integer with less number of bits

Status
Not open for further replies.

cyboman

Member level 4
Joined
Mar 9, 2010
Messages
71
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
USA
Activity points
1,808
i have two integers, both with different ranges. i need to take lower bits of the integer with a larger range and assign them to the one with a lower range

i.e.

Code:
signal less_bits : integer range 0 to 3;
signal more_bits : integer range 0 to 4;

more_bits <= 4;
less_bits <= more_bits -- less bits would be equal to 0

does anybody know of any trick in vhdl to do that? is it even possible?
 

What you have is a 3bit number and a 4 bit number, you can probably assign the lower 3 bits of more_bits to the lower_bits but i don't know the function for integers,
for std_logic_vector it would be less_bits<=more_bits(2 downto 0)

Alex
 

What you have is a 3bit number and a 4 bit number, you can probably assign the lower 3 bits of more_bits to the lower_bits but i don't know the function for integers,
for std_logic_vector it would be less_bits<=more_bits(2 downto 0)

Alex

i knew that. i was looking something specifically for integers.
 

integers in VHDL dont have bits. you'll have to cast both to an unsigned an do it that way. This is the point of the type system in VHDL.
The code from your origional code is illegal because the subtype of less bits only goes to 3.

so you could do this (and get a truncation warning):

less_bits <= to_integer( to_unsigned(more_bits, 2) );
 

It depends on how you want to treat out-of-range numbers. If you are only trying to get least significant bits, you can use the 'mod' operator.

less_bits <= more_bits mod 4;

If you were trying to saturate, then min(3, more_bits); would work.

You can do a non-power-of-2 mod for sure in sim, but I can't remember if it is synthesizable.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top