Skip to content

Instantly share code, notes, and snippets.

@NVolcz
Created January 26, 2014 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NVolcz/8635416 to your computer and use it in GitHub Desktop.
Save NVolcz/8635416 to your computer and use it in GitHub Desktop.
public T[] generate_crc_table3(T)(T polynomial, T initialValue, bool refin) {
T[] table = new T[](256);
int i, j;
T bit, crc;
auto order = T.sizeof * 8;
for(i = 0; i < 256; i++) {
crc = cast(T)i;
if(refin) {
crc=reflect(crc, 8);
}
crc <<= order-8;
for(j = 0; j < 8; j++) {
bit = crc & crchighbit;
crc<<= 1;
if (bit) crc^= polynom;
}
if (refin) {
crc = reflect(crc, order);
}
table[i]= crc;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment