1
0
mirror of https://github.com/myhdl/myhdl.git synced 2025-01-24 21:52:56 +08:00
Christopher Felton e3a42a6443
Updated docs for 0.11 release (#315)
* updated docs for 0.11 release

* revert docs back to the myhdl RTD
2019-05-19 15:21:04 -05:00

31 lines
677 B
Python

from myhdl import intbv, concat
COSET = 0x55
def calculateHec(header):
""" Return hec for an ATM header, represented as an intbv.
The hec polynomial is 1 + x + x**2 + x**8.
"""
hec = intbv(0)
for bit in header[32:]:
hec[8:] = concat(hec[7:2],
bit ^ hec[1] ^ hec[7],
bit ^ hec[0] ^ hec[7],
bit ^ hec[7]
)
return hec ^ COSET
headers = ( 0x00000000,
0x01234567,
0xbac6f4ca
)
def main():
for header in headers:
print(hex(calculateHec(intbv(header))))
if __name__ == '__main__':
main()