Einzelnen Beitrag anzeigen

Benutzerbild von Phoenix
Phoenix
(Moderator)

Registriert seit: 25. Jun 2002
Ort: Hausach
7.611 Beiträge
 
#3

AW: Visual Basic zu Delphi

  Alt 23. Feb 2023, 12:56
Mal ChatGPT gefragt:

Zitat von Phoenix:
This code block is visual basic:

begin
crc := (crc >> 8) Xor crc16tab((crc Xor CByte(Asc(ch))) And &HFF);
end;

Please translate this to Delphi code.
Zitat von ChatGPT:
Sure! Here is the equivalent Delphi code for the provided Visual Basic code block:
Code:
crc := (crc shr 8) xor crc16tab[(crc xor Byte(Ord(ch))) and $FF];
Assuming crc is a 16-bit unsigned integer variable, and crc16tab is an array of 256 16-bit unsigned integers.

Note that shr is the Delphi equivalent of the >> right-shift operator in Visual Basic. Byte(Ord(ch)) is used to convert the ASCII character ch to a byte value, which is required by the crc16tab array. The $FF hexadecimal value is used to perform a bitwise AND operation with the byte value, ensuring that only the lower 8 bits are used in the computation.
Irgendwie cool. Und erschreckend. Ich habe ihm die Tabelle ja nicht mitgegeben, aber das Ding "rät" das es die Tabelle sein muss.
Sebastian Gingter
Phoenix - 不死鳥, Microsoft MVP, Rettungshundeführer
Über mich: Sebastian Gingter @ Thinktecture Mein Blog: https://gingter.org
  Mit Zitat antworten Zitat