德尔福中的按位补码.(翻译 C# ~ 运算符)



我有用于计算发送到特定串行设备的命令的校验和字节的 C# 代码。我需要帮助将此功能转换为适用于Windows的Delphi 10.x以及Delphi Android(如果它不同(。

C# 代码

public byte CheckSum(byte[] btAryBuffer, int nStartPos, int nLen)
{
byte btSum = 0x00;
for (int nloop = nStartPos; nloop < nStartPos + nLen; nloop++ )
{
btSum += btAryBuffer[nloop];
}
return Convert.ToByte(((~btSum) + 1) & 0xFF);
}

德尔福密码

function CalcCheckSum(buffer: TArray<byte>; nStartPos: Integer; nLen: Integer): Byte;
var i: Integer;
begin
Result := 0;
i := nStartPos;
while i < nStartPos + nLen do
begin
Result := Result + buffer[i];
Inc(i);
end; 
Result := ???
end;
Result := ((not Result) + 1) and $FF;

最新更新