fn crc_update(data: &[u8], crc: u32) -> u32 {
    let mut crc = crc;
    for c in data {
        for i in [0x80u8, 0x40u8, 0x20u8, 0x10u8, 0x08u8, 0x04u8, 0x02u8, 0x01u8].iter() {
            let mut bit = (crc & 0x80000) != 0; // The bit about to be shifted out
            if (c & i) != 0 {
                bit = !bit;
            }
            crc <<= 1;
            if bit {
                crc ^= 0xc4047;
            }
        }
    }

    crc & 0xfffff // Constrain to 20 bits
}
// CRC-20 with poly 0x1c4047
// Detects errors (up to and including Hamming distance 6)
// in 494 bits of data. Good enough for us (400 bits).
// Much thanks to https://users.ece.cmu.edu/~koopman/crc/
CRC-20 with poly 0x1c4047
Detects errors (up to and including Hamming distance 6)
in 494 bits of data. Good enough for us (400 bits).
CRC - 20 with poly 0x1c4047 Detects errors ( up to and including Hamming distance 6 ) in 494 bits of data . Good enough for us ( 400 bits ) .
fn crc_update(data: &[u8], crc: u32) -> u32 {
    let mut crc = crc;
    for c in data {
        for i in [0x80u8, 0x40u8, 0x20u8, 0x10u8, 0x08u8, 0x04u8, 0x02u8, 0x01u8].iter() {
            let mut bit = (crc & 0x80000) != 0; // The bit about to be shifted out
            if (c & i) != 0 {
                bit = !bit;
            }
            crc <<= 1;
            if bit {
                crc ^= 0xc4047;
            }
        }
    }
    crc & 0xfffff // Constrain to 20 bits
}
fn crc_update ( data : & [ u8 ] , crc : u32 ) -> u32 { let mut crc = crc ; for c in data { for i in [ 0x80u8 , 0x40u8 , 0x20u8 , 0x10u8 , 0x08u8 , 0x04u8 , 0x02u8 , 0x01u8 ] . iter ( ) { let mut bit = ( crc & 0x80000 ) != 0 ; // The bit about to be shifted out if ( c & i ) != 0 { bit = ! bit ; } crc <<= 1 ; if bit { crc ^= 0xc4047 ; } } } crc & 0xfffff // Constrain to 20 bits }
CRC-20 with poly 0x1c4047
Detects errors (up to and including Hamming distance 6)
in 494 bits of data.
CRC - 20 with poly 0x1c4047 Detects errors ( up to and including Hamming distance 6 ) in 494 bits of data .
data
&[u8]
crc
u32
data
&[u8]
crc
u32