Thursday, March 14, 2013

BINARY TO GRAY CONVERTER


This program is to convert binary number into gray code. The logic behind conversion is the most significant bit is same and the consequent bits are the result of ex-or of binary bits.  

module bin_to_gray(
input clk,
input [2:0]binary,
output reg[2:0]gray
);
always@(posedge clk)
begin
gray[2] = binary[2];
gray[1] = binary[2] ^ binary[1];
gray[0] = binary[1] ^ binary[0];
end
endmodule

No comments: