Monday, 10 September 2012

VHDL code for Binary to Gray converter

Below is the VHDL code for  4bit binary to gray code converter. It can done here by using dataflow modelling. You can use the modelling to reverse the conversion eg. Gray to Binary conversion.

CODE FOR 4 BIT Binary To Gray Converter

=========================================================================

library ieee;
use ieee.std_logic_1164.all;

entity binary_2_gray is
port(b:in std_logic_vector(3 downto 0);

g:out std_logic_vector(3 downto 0));
end binary_2_gray;

architecture dataflow of binary_2_gray is
begin

g(3)<=b(3);
g(2)<=b(3) xor b(2);
g(1)<=b(2) xor b(1);
g(0)<=b(1) xor b(0);
end dataflow;
=========================================================================
Like us on facebook and leave comments

Comments System