M
Mark
I'm trying to elegantly convert a std_logic_vector(upper downto lower)
to an integer without sign extension using ieee.numeric_std with upper
and lower taking on values from 31 to 0 and with upper >= lower. I
cannot seem to find a syntax that doesn't generate truncation
warnings, or relies on doing some comparison.
If I use:
i:= to_integer( signed( slv(upper downto lower)));
I'll get sign extension if upper==lower (which I don't want).
To avoid sign extension, I've tried:
i:= to_integer( signed( '0' & slv(upper downto lower)));
That works great until upper=31, and lower=0---leading to a to_signed
truncation warning (since in this case we're creating a 33-bit vector
and reducing it to a 32-bit integer).
I could just check if upper==lower, and break the conversion into two
cases, but I'm wondering if there's a cleaner, more elegant way of
handling this conversion without warnings.
to an integer without sign extension using ieee.numeric_std with upper
and lower taking on values from 31 to 0 and with upper >= lower. I
cannot seem to find a syntax that doesn't generate truncation
warnings, or relies on doing some comparison.
If I use:
i:= to_integer( signed( slv(upper downto lower)));
I'll get sign extension if upper==lower (which I don't want).
To avoid sign extension, I've tried:
i:= to_integer( signed( '0' & slv(upper downto lower)));
That works great until upper=31, and lower=0---leading to a to_signed
truncation warning (since in this case we're creating a 33-bit vector
and reducing it to a 32-bit integer).
I could just check if upper==lower, and break the conversion into two
cases, but I'm wondering if there's a cleaner, more elegant way of
handling this conversion without warnings.