Verilog Examples -> Code converters : Binary to Gray & Gary to Binary

1) Binary to gray code converter 

Gray code – also known as Cyclic Code is defined as an ordering of the binary number system such that each incremental value can only differ by one bit. In gray code, while traversing from one step to another step only one bit in the code group changes. That is to say that two adjacent code numbers differ from each other by only one bit.

Logic Circuit to convert Binary to Gray 


 

Verilog Code for Binary to Gray code


TestBench for DUT


Output:

binary=0000 gray=0000
binary=0001 gray=0001
binary=0010 gray=0011
binary=0011 gray=0010
binary=0100 gray=0110
binary=0101 gray=0111
binary=0110 gray=0101
binary=0111 gray=0100
binary=1000 gray=1100
binary=1001 gray=1101
binary=1010 gray=1111
binary=1011 gray=1110
binary=1100 gray=1010
binary=1101 gray=1011
binary=1110 gray=1001
binary=1111 gray=1000

 Link for Code : Edaplayground

 

2) Gray to Binary  Code Converter

Verilog Code for Gray to Binary converter



TestBench for DUT


 Output

Gray=0000 Binary=0000
Gray=0001 Binary=0001
Gray=0010 Binary=0011
Gray=0011 Binary=0010
Gray=0100 Binary=0111
Gray=0101 Binary=0110
Gray=0110 Binary=0100
Gray=0111 Binary=0101
Gray=1000 Binary=1111
Gray=1001 Binary=1110
Gray=1010 Binary=1100
Gray=1011 Binary=1101
Gray=1100 Binary=1000
Gray=1101 Binary=1001
Gray=1110 Binary=1011
Gray=1111 Binary=1010

 

Link for Code : Edaplyground 

Thank you for reading have a nice day. 

Share:
Copyright © VLSI Verification Concepts . Designed by OddThemes