Skip to content

Instantly share code, notes, and snippets.

@NVolcz
Created Jan 26, 2014
Embed
What would you like to do?
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