Skip to content

Instantly share code, notes, and snippets.

@Btremaine
Last active August 22, 2021 19:55
Show Gist options
  • Save Btremaine/c3a48e0baab539e0cb562635f0e6ecc6 to your computer and use it in GitHub Desktop.
Save Btremaine/c3a48e0baab539e0cb562635f0e6ecc6 to your computer and use it in GitHub Desktop.
prbs C code Example 1
// replicated from wikipeda, https://en.wikipedia.org/wiki/Pseudorandom_binary_sequence
// Example of PRBS7
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
int main(int argc, char* argv[]) {
uint8_t start = 0x02;
uint8_t a = start;
int i;
for (i = 1;; i++) {
int newbit = (((a >> 6) ^ (a >> 5)) & 1);
a = ((a << 1) | newbit) & 0x7f;
printf("%x\n", a);
if (a == start) {
printf("repetition period is %d\n", i);
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment