resize function with example

Status
Not open for further replies.
numeric_std has resize functions for signed and unsigned types.

here is the resize function for signed types

Code:
function RESIZE (ARG: SIGNED; NEW_SIZE: NATURAL) return SIGNED is
  alias invec : SIGNED (ARG'length-1 downto 0) is ARG ;
  variable RESULT: SIGNED (NEW_SIZE-1 downto 0) ;
  constant bound : NATURAL:= MIN(ARG'length,RESULT'length)-2 ;
begin
  if (NEW_SIZE<1) then return NAS; end if;
  RESULT:= (others=>ARG(ARG'left)) ;
  if bound >= 0 then 
    RESULT(bound downto 0) := invec(bound downto 0) ;
    end if;
  return RESULT;
end RESIZE ;
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…