Forum Discussion
Altera_Forum
Honored Contributor
13 years ago --- Quote Start --- Hi, Is there a way to add two unsigned numbers and extract only the x most significant bits from it in one step? I want something like this: sum <= resize(number1 + number2,4) Instead of: temp <= number1 + number2 sum <= temp(7 downto 4) The existing resize function in numeric_std drops the msb's, I want the lsb's dropped. Thanks in advance! --- Quote End --- assuming you are using type 'unsigned'
sum <= to_unsigned( (to_integer(number1)+to_integer(number2)) / 16 , 4) ;
but this works even nicer :sum <= unsigned( number21 + number22 )(7 downto 4) ;