Optical 4-bit binary to gray and gray to binary code conversion has been demonstrated. The encoders are designed by implementing XOR gates in optical domain. Phase modulation in Mach–Zehnder interferometer has been exploited to achieve results at considerably high data rates of up to 60 Gbps. Also, the designs, being reversible in nature, will amount to less power consumption when embedded in an optical network. Performance parameters of the design, such as factor and extinction ratio, are analyzed based on simulation results carried out using comprehensive design suite OptiSystem-13.