
entity PRIORITY_ENCODER is
   port (W : in BIT_VECTOR (3 downto 0);
         Y : out BIT_VECTOR (1 downto 0);
         Z : out BIT);
end PRIORITY_ENCODER;

architecture SEQ of PRIORITY_ENCODER is
begin
   process (W)
   begin
      Z <= '1';
      if (W(3) = '1') then
         Y <= "11";
      elsif (W(2) = '1') then
         Y <= "10";
      elsif (W(1) = '1') then
         Y <= "01";
      elsif (W(0) = '1') then
         Y <= "00";
      else
         Z <= '0';
      end if;
   end process;
end SEQ;

architecture CON of PRIORITY_ENCODER is
begin
   Z <= '0' when W = "0000" else
        '1';
   Y <= "11" when W(3) = '1' else
        "10" when W(2) = '1' else
        "01" when W(1) = '1' else
        "00" when W(0) = '1';
end CON;
