Hi,
String is always UTF16. So if you have your text in a string, you always have it in 2 bytes per char. What I would use is:
function CalcCRC(S:String): DWORD;
var i: integer;
CRC : DWORD;
t : TArray<byte>;
begin
t := TEncoding.Unicode.GetBytes(S);
CRC := 0;
// CRCvalue := (CRCvalue SHR 8) XOR
// Table[ q^ XOR (CRCvalue AND $000000FF) ];
for i:= 0 to Length(t) do CRC := (CRC SHR 8) XOR const_table[t[i] XOR (CRC AND $000000FF)];
CalcCRC := CRC;
end;
That is, use TEncoding.GetBytes to get the bytes representing the string, then run the CRC in those bytes. There is no need to convert to UTF8
Edit: I forgot to remove size in the code example.
Edit2: The formatting of the text was wrong and t[i] was replaced by t
Adrian Gallero2018-04-08 13:08:28