PreviousNext
Java
Help > Appendix > CRC Calculation > Java

/**

 * Returns new value of CRC.

 * @param crc current value of CRC

 * @param value input data byte

 * @return updated value of CRC

 */

static short updateCRC(short crc, short value) {

    for ( int bitLoop = 8; bitLoop != 0; --bitLoop, value >>= 1 ) {

        if ( ( ( crc ^ value ) & 0x01 ) != 0 ) {

            crc = (short)( ( crc >> 1 ) ^ 0x8C );

        } else {

            crc >>= 1;

        }

    }

    return crc;

}