Created
February 16, 2019 13:51
-
-
Save beyondlimits/9bebb798060dde6631871b76da4ce837 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| #-*- coding: utf-8 -*- | |
| # Computes bit parity. When x represented as binary number | |
| # has odd number of ones, 1 is returned. Otherwise 0 is returned. | |
| def parity(x): | |
| i = 1 | |
| y = x | |
| while x: | |
| x >>= i | |
| y ^= y >> i | |
| i <<= 1 | |
| return y & 1 | |
| # bits - number of bits in register, used to know where to put incoming bit. | |
| def next_word(previous_word, polynomial, bits): | |
| return (previous_word >> 1) | (parity(previous_word & polynomial) << (bits-1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment