//! CRC16-CCITT-FALSE frame integrity check.

/// Compute the CRC16-CCITT-FALSE of `data` (poly `0x1021`, init `0xFFFF`, MSB-first).
pub fn crc16_ccitt(data: &[u8]) -> u16 {
    let mut crc: u16 = 0xFFFF;
    for &b in data {
        crc ^= (b as u16) << 8;
        for _ in 0..8 {
            crc = if crc & 0x8000 != 0 {
                (crc << 1) ^ 0x1021
            } else {
                crc << 1
            };
        }
    }
    crc
}
