library ieee;
use ieee.std_logic_1164.all;

entity four_bit_segment is
    port (x : in std_logic_vector(3 downto 0);
          pins : out std_logic_vector(6 downto 0));
end entity;

architecture rtl of four_bit_segment is
begin
    pins(0) <= (not x(0) and not x(1) and x(2)) or (x(0) and not x(1) and not x(2) and not x(3));
    pins(1) <= (not x(0) and x(1) and x(2)) or (x(0) and not x(1) and x(2));
    pins(2) <= (not x(0) and x(1) and not x(2));
    pins(3) <= (not x(0) and not x(1) and x(2)) or (x(0) and not x(1) and not x(2) and not x(3)) or (x(0) and x(1) and x(2));
    pins(4) <= (not x(1) and x(2)) or x(0);
    pins(5) <= (x(1) and not x(2)) or (x(0) and not x(2) and not x(3)) or (x(0) and x(1));
    pins(6) <= (not x(1) and not x(2) and not x(3)) or (x(0) and x(1) and x(2));
end architecture;

library ieee;
use ieee.std_logic_1164.all;

entity binary_to_decimal is
    port (SW : in std_logic_vector(9 downto 0);
          HEX1, HEX0 : out std_logic_vector(6 downto 0));
end entity;
architecture rtl of binary_to_decimal is
    signal v, tens, ones_digit, adjusted, mask : std_logic_vector(3 downto 0);
    signal z : std_logic;
begin
    v <= SW(3 downto 0);
    z <= '0'; -- Identify inputs above nine.
    adjusted(3) <= '0';
    adjusted(2) <= '0'; -- Complete the six-row conversion table.
    adjusted(1) <= '0';
    adjusted(0) <= v(0);
    mask <= (others => z);
    ones_digit <= (v and not mask) or (adjusted and mask);
    tens <= "000" & z;
    left_digit : entity work.four_bit_segment port map (tens, HEX1);
    right_digit : entity work.four_bit_segment port map (ones_digit, HEX0);
end architecture;
