Binary to Gray Converter Design Simulation using Xilinx Vivado – JNTUH CMOS VLSI LAB 04

87 / 100
Reading Time: 10 minutes
binary to gray
Binary to Gray Conversion Implementation Schematic

In this technical exploration, we delve into the intricacies of designing a 4-bit binary to Gray code converter, a pivotal component in minimizing bit transition errors in digital systems. This experiment, tailored for the CMOS VLSI Design Laboratory curriculum of B.Tech. III Year II Semester under JNTUH, employs Xilinx Vivado to simulate the conversion process. Through a meticulous synthesis of Verilog coding and FPGA board simulation, this guide provides a step-by-step methodology to implement and validate the converter, aiming to equip students with practical skills in VLSI design principles and digital error minimization techniques.

Thank you for reading this post, don't forget to share! website average bounce rate Buy traffic for your website


Lab Report

AIM: Design of 4 bit binary to gray code converter

Apparatus / Software required:

  • Xilinx Vivado Design Suite
  • Windows Machine
  • Notepad or any text editor


In binary code, numbers are represented using two symbols, ‘0’ and ‘1’. Gray code is a variation where each successive number differs from the previous one by only one bit, reducing the potential for errors during transitions. The conversion logic involves keeping the most significant bit (MSB) the same as in binary, while each subsequent bit is determined by an XOR operation between the adjacent bits in the binary number. This simple, yet effective method ensures minimal error in digital communication systems, making it ideal for applications requiring high reliability, such as digital encoders and telecommunications.

Binary to Grey Conversion

The output bits of a Gray code (G3, G2, G1, G0) generated from a 4-bit binary input (B3, B2, B1, B0) can be described by the following equations:

  • G3 (Most Significant Bit): ( G3 = B3 )
    • The most significant bit of the Gray code is the same as the most significant bit of the binary input.
  • G2: ( G2 = B3 xor B2 )
    • The second bit of the Gray code is the result of an XOR operation between the third and second bits of the binary input.
  • G1: ( G1 = B2 xor B1 )
    • The third bit of the Gray code is obtained by performing an XOR operation between the second and first bits of the binary input.
  • G0 (Least Significant Bit): ( G0 = B1 xor B0 )
    • The least significant bit of the Gray code is the result of an XOR operation between the first and zeroth bits of the binary input.

These equations succinctly capture the relationship between the binary input and Gray code output, showcasing the bit-wise transformation process involved in converting a 4-bit binary number to its corresponding Gray code representation.

To complete the table with the corresponding Gray code for each binary number, we use the logic that the most significant bit (G3) is the same as B3, and each subsequent bit is obtained by performing an XOR operation between the adjacent bits of the binary input.


This table now accurately represents the conversion from binary to Gray code for 4-bit numbers, useful for understanding the conversion process and verifying the output of a binary to Gray code converter.


  1. Open Notepad or any text editor on a Windows machine and write the Verilog code for the 8-to-1 multiplexer and 1-to-8 demultiplexer.
  2. Save the files with a .v extension, selecting “All Files” as the save type.
  3. Launch Xilinx Vivado from the desktop or start menu.
  4. Create a new project, naming it appropriately (e.g., b2g_conversion_lab) and choosing the project’s storage location.
  5. Ensure “RTL Project” is selected and specify sources at this time by pointing to the Verilog source code and testbench files you’ve created.
  6. Select the FPGA board or part targeted for this project using the search function.
  7. Run Behavioral Simulation to compile the Verilog files and execute the simulation based on your testbench.
  8. Inspect the waveform viewer to verify that the outputs match the expected results based on your testbench scenarios.
  9. Proceed with Synthesis and Implementation phases to optimize the design for performance and resource utilization.
  10. Analyze the simulation results, synthesized schematic, and implementation reports, making necessary adjustments to refine your design.


Binary to Gray Converter RTL Code in Verilog

Testbench for 4-bit Binary to Gray Code Converter implementation in Verilog

Expected Results:

After following the steps correctly, the simulation in Xilinx Vivado will show the expected behavior for binary to gray conversion, aligning with the input and output relations defined in the theory section.

expected wavefom
Expected Waveform


This lab experiment solidifies the understanding and application of binaruy to gray convesion in digital design, showcasing the practical use of Xilinx Vivado in simulating complex VLSI components.

Viva-Voce Questions:

  1. What is the purpose of converting a binary number to Gray code?
    • To minimize the possibility of errors during data transfer by ensuring that only one bit changes between consecutive values.
  2. Can you explain the principle behind the conversion from binary to Gray code?
    • The conversion principle involves the most significant bit (MSB) remaining the same, and each subsequent bit being the result of an XOR operation between the adjacent bits of the binary input.
  3. What is Verilog?
    • Verilog is a hardware description language (HDL) used to model electronic systems. It enables the design and testing of digital circuits in a simulation environment.
  4. Why is Xilinx Vivado used for the synthesis of Verilog designs?
    • Xilinx Vivado is an integrated development environment (IDE) that provides tools for the design, simulation, and synthesis of digital circuits, making it suitable for Verilog-based designs.
  5. How do you define a 4-bit input in Verilog for a binary to Gray code converter?
    • A 4-bit input can be defined in Verilog using the syntax input [3:0] binary;, where [3:0] specifies a 4-bit wide vector.
  6. What is the role of the XOR operation in the conversion from binary to Gray code in your Verilog implementation?
    • The XOR operation is used to generate each bit of the Gray code (except for the MSB) by comparing adjacent bits of the binary input, ensuring that only one bit changes at a time.
  7. Can you describe the test bench used for simulating the binary to Gray code converter in Vivado?
    • A test bench in Vivado for this converter would include a module that generates various 4-bit binary inputs, applies them to the converter, and checks the Gray code output for correctness.
  8. What are some challenges you faced while implementing the converter in Verilog and how did you overcome them?
    • This could include debugging syntax errors, ensuring the logic correctly implements the XOR operations, or issues with simulation. Overcoming them typically involves iterative testing and debugging.
  9. How does the synthesis report in Vivado help in evaluating the performance of the binary to Gray code converter?
    • The synthesis report provides details on resource utilization (like logic gates used) and timing information, helping to assess the efficiency and speed of the converter.
  10. What would be the impact of using a 4-bit binary to Gray code converter in a digital communication system?
    • It reduces the risk of errors during data transmission, particularly in scenarios where signal timing might cause multiple bits to change simultaneously if binary encoding were used.

Complete Detailed Procedure for Simulation in Xilinx Vivado

  1. Preparation: Before opening Vivado, ensure all Verilog source files and testbenches are correctly written and saved.
  1. Project Creation: Launch Vivado, create a new project, and specify your project’s name and location.
  1. Adding Files: Include your Verilog source and testbench files in the project setup.
  1. Selecting Target Device: Choose the FPGA board or part you’re targeting, based on your project requirements.
  1. Running Simulation: Utilize the Behavioral Simulation feature to compile and simulate your Verilog files.
  1. Synthesis and Implementation: After verifying the simulation results, proceed with synthesis and implementation to optimize your design.
  1. Analysis: Review synthesized schematics, implementation reports, and simulation results to ensure the design meets all criteria.
  1. Adjustments and Finalization: Make any necessary design adjustments based on your analyses and save your project.

Additional Reading:

  • FPGA Design Fundamentals
  • Verilog for Beginners
  • Advanced Digital Design with the Verilog HDL


FAQ: Xilinx Vivado

  1. What is Xilinx Vivado?
    • Xilinx Vivado is an integrated development environment (IDE) designed for FPGA (Field Programmable Gate Array) development, offering synthesis, analysis, simulation, and implementation capabilities for digital circuit design.
  2. How does Vivado differ from ISE (Integrated Synthesis Environment)?
    • Vivado is the successor to Xilinx ISE, offering a more modern user interface, improved synthesis and analysis tools, and better support for high-capacity FPGAs. Vivado focuses on newer FPGA architectures like the UltraScale and UltraScale+ series.
  3. Can Vivado be used for programming in Verilog and VHDL?
    • Yes, Vivado supports both Verilog and VHDL for designing digital circuits, allowing users to simulate, synthesize, and implement designs using either hardware description language.
  4. Is there a free version of Vivado available?
    • Yes, Xilinx offers a Vivado Design Suite WebPACK Edition, which is free and includes enough features for students, hobbyists, and researchers to design and program FPGAs.
  5. What are the system requirements for installing Vivado?
    • Vivado requires a Windows or Linux operating system with specific hardware requirements, including a 64-bit processor, at least 8 GB of RAM (32 GB recommended for large designs), and around 20 GB of free disk space for installation.
  6. How can I learn to use Vivado?
    • Xilinx offers comprehensive documentation, tutorials, and video training courses for Vivado. Many universities and online platforms also provide courses and materials on FPGA design using Vivado.
  7. What is the role of the Vivado High-Level Synthesis (HLS)?
    • Vivado HLS allows designers to write C, C++, or SystemC code to describe their hardware functions, which Vivado HLS then synthesizes into optimized VHDL/Verilog code, enabling a higher level of abstraction in design.
  8. Can I simulate my FPGA design without a physical board using Vivado?
    • Yes, Vivado includes a simulator that allows you to test and debug your FPGA designs thoroughly before deploying them to actual hardware.
  9. How does Vivado manage version control and collaborative work?
    • Vivado integrates with version control systems like Git and Subversion, enabling teams to collaborate on projects efficiently. It also supports project sharing and IP (Intellectual Property) reuse to facilitate teamwork.
  10. What kind of support does Xilinx offer for Vivado users?
    • Xilinx provides a range of support options for Vivado users, including detailed documentation, a user community forum, technical support for licensed users, and training programs for both beginners and advanced users.


  • Official Xilinx Vivado Documentation
  • Digital Design and Computer Architecture by Harris & Harris
  • FPGA Prototyping by Verilog Examples by Pong P. Chu

Here are the reference links formatted for inclusion in your blog:



Dr. Honey Durgaprasad Tiwari, both the CTO at INKOR Technologies Private Limited, India, and a dedicated academic researcher, brings a wealth of expertise. With a Post-Doctoral stint at Sungkyunkwan University, Ph.D. in Electronic, Information and Communication Engineering from Konkuk University, Seoul, South Korea, and M.Tech in Embedded Electronic Systems from VNIT Nagpur, his research legacy spans wireless power transfer, medical imaging, and FPGA innovation. Notably, he has authored 40+ SCI papers, conference contributions, and patents, leaving an indelible mark on these fields. Holding pivotal Academic Administrative roles, including Head of Department and IQAC Coordinator, he passionately channels his insights into concise and impactful blogs, enriching the tech discourse. 🚀🔬📚

Leave a Comment

Binary to Gray Converter Design Simulation using X…

by Dr. Honey Durgaprasad Tiwari time to read: 8 min