1
0
mirror of https://github.com/myhdl/myhdl.git synced 2024-12-14 07:44:38 +08:00
myhdl/cosimulation/test/bin2gray.py

19 lines
313 B
Python
Raw Normal View History

2005-12-14 14:41:53 +00:00
from myhdl import *
2003-04-24 11:04:01 +00:00
def bin2gray(B, G, width):
""" Gray encoder.
B -- input intbv signal, binary encoded
G -- output intbv signal, gray encoded
width -- bit width
"""
2005-12-14 14:41:53 +00:00
@always_comb
def logic():
2003-04-24 11:04:01 +00:00
for i in range(width):
G.next[i] = B[i+1] ^ B[i]
2005-12-14 14:41:53 +00:00
return logic
2003-04-24 11:04:01 +00:00