-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
which is CRC-16-CCITT? #54
Comments
@clouds56 Similar issue, I couldn't get the right combo using crc-rs 1.8. But crc16 // crc16 = "0.4"
const TEST_CASES : &[(&[u8], u16)] = &[
(b"123456789", 0xE5CC),
(&[65], 0x9479),
(&[3, 5, 11], 1730),
(&['A' as u8; 256], 0xE938),
];
for &(input, expected) in TEST_CASES.iter() {
let mut state = crc16::State::<crc16::AUG_CCITT>::new();
state.update(input);
assert_eq!(state.get(), expected);
}
assert_eq!(crc16::State::<crc16::CCITT_FALSE>::calculate(b"123456789"), 0x29B1); |
@osialr , thanks for the link, according to code in crc16 // (BIT_REVERSE_TABLE[(crc & 0xFF) as usize] << 8) | BIT_REVERSE_TABLE[(crc >> 8) as usize]
crc = ((crc >> 8) | ((msg[i] as u16) << 8)) ^ $table[(crc & 0xff) as usize] and crc = ((crc << 8) | (msg[i] as u16)) ^ $table[((crc >> 8) & 0xFF) as usize]; I think it impossible to use this |
@mrhooray wdyt about publishing a release candidate |
Published 2.0.0-rc.1. There were some timeouts/hiccups - please help check from your end. |
So, in the end, in crc-v2.1.0, which is the right one for CRC16-CCITT? |
Upon a closer look at the catalogue sources, sounds like this is the one: /* slightly trimmed from rusty details */
CRC_16_IBM_3740 { poly: 0x1021, init: 0xffff, refin: false, refout: false, xorout: 0x0000, check: 0x29b1, residue: 0x0000 }; http://srecord.sourceforge.net/crc16-ccitt.html
Am I right? In which case, why won't we have an alias for it? |
CCITT is confusing because it's commonly misrepresented. You probably want We shouldn't have an alias for CCITT because it's not clear what the "correct" poly and init values are. It's better to use the less ambiguous terms. |
How to calculate the well known CRC-16-CCITT with poly = 0x1021?
according to https://www.lammertbies.nl/comm/info/crc-calculation and http://srecord.sourceforge.net/crc16-ccitt.html, we shall get 0xE5CC or 0x29B1 for bytes
b"123456789"
, but I could not manage to get it.The combination I've tried the combination of poly in
[0x8408, 0x1021]
and init in[0, !0x1D0F]
, but with no luck.I even tried poly of
[0x811, 0x8810]
according to this https://en.wikipedia.org/wiki/Cyclic_redundancy_check.The text was updated successfully, but these errors were encountered: