Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@aurimasniekis
Created October 25, 2017 11:51
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 aurimasniekis/2758c8629fb6fec4bab60d71a7ac98ad to your computer and use it in GitHub Desktop.
Save aurimasniekis/2758c8629fb6fec4bab60d71a7ac98ad to your computer and use it in GitHub Desktop.
uint32_t MokaFramer::crc32Step(uint32_t crc, uint8_t byte) {
crc ^= byte;
for (uint32_t j = 0; j < 8; j++) {
uint32_t mask = (uint32_t) -(crc & 1U);
crc = (crc >> 1) ^ (0xedb88320U & mask);
}
return crc;
}
def crc_step(crc : UInt32, byte : UInt8)
crc ^= byte
[0..7].each do |j|
mask = (crc & 1_u32)
mask = -1 * mask
crc = (crc >> 1_u32) ^ (0xedb88320_u32 & mask)
end
crc
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment