-- numconv.vhd: numeric conversion between two's complement -- and sign-magnitude -- Dan R. K. Ports -- 6.111 Lab 3, 2003/10/22 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity numconv is generic ( width : integer := 8); port ( input : in std_logic_vector(width-1 downto 0); output : out std_logic_vector(width-1 downto 0)); end numconv; architecture behavioral of numconv is begin -- behavioral -- purpose: convert input between sign/magnitude and two's complement -- type : combinational -- inputs : input -- outputs: output convert: process (input) begin -- process convert if input(width-1) = '0' then output <= input; else if input(width-2 downto 0) = 0 then output <= (others => '0'); else output(width-1) <= '1'; output(width-2 downto 0) <= (not input(width-2 downto 0)) + 1; end if; end if; end process convert; end behavioral;