PreviousNext
Pascal/Delphi
Help > Appendix > CRC Calculation > Pascal/Delphi

/// <summary>

/// Computes 1-Wire CRC

/// </summary>

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

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

procedure UpdateOneWireCrc ( value: byte; var crc: byte );

var

  bitLoop: integer;

begin

  for bitLoop := 8 downto 1 do begin

    if ( ( ( crc xor value ) and $01 ) <> 0 ) then

      crc := ( crc shr 1 ) xor $8C

    else

      crc := crc shr 1;

    value := value shr 1;

  end;

end;