advance method
Advances state with one packed input beat.
Reflected configurations consume bit zero first. Non-reflected configurations consume the most-significant bit first.
Implementation
BigInt advance(BigInt state, BigInt beat, {required int beatWidth}) {
if (beatWidth <= 0) {
throw RohdHclException('CRC beat width must be positive.');
}
if (beat.isNegative || beat >= (BigInt.one << beatWidth)) {
throw RohdHclException(
'CRC input $beat does not fit in $beatWidth bits.',
);
}
final bitIndices = reflectInput
? List<int>.generate(beatWidth, (index) => index)
: List<int>.generate(beatWidth, (index) => beatWidth - 1 - index);
for (final bitIndex in bitIndices) {
state = advanceBit(
state,
bit: ((beat >> bitIndex) & BigInt.one) != BigInt.zero,
);
}
return state;
}