1
0
mirror of https://github.com/myhdl/myhdl.git synced 2025-01-24 21:52:56 +08:00
myhdl/cosimulation/test/bin2gray.py

17 lines
359 B
Python
Raw Normal View History

2003-04-24 11:04:01 +00:00
from __future__ import generators
from myhdl import Signal, delay, Simulation, intbv, bin
def bin2gray(B, G, width):
""" Gray encoder.
B -- input intbv signal, binary encoded
G -- output intbv signal, gray encoded
width -- bit width
"""
while 1:
yield B
for i in range(width):
G.next[i] = B[i+1] ^ B[i]