PreviousNext
C#
Help > Appendix > CRC Calculation > C#

/// <summary>

/// Computes 1-Wire CRC

/// </summary>

/// <param name="value">Input data byte</param>

/// <param name="crc">Updated CRC</param>

static void UpdateOneWireCrc ( byte value, ref byte crc )

{

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

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

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

    else

      crc >>= 1;

}