Obsolate
asked on
CRC16 Calculation Algorithm (good, but...)
Polynomial: x16 + x12 + x5 + 1
Start Value: 0xFFFF
CRC_POLYNOM = 0x8408;
CRC_PRESET = 0xFFFF;
C-Example:
unsigned internal CRC = CRC_PRESET;
for (i = 0; i < cnt; i++) /* cnt = number of protocol bytes without CRC */
{
crc ^= DATA[i];
for (j = 0; j < 8; j++)
{
if (crc & 0x0001)
crc = (crc >> 1) ^ CRC_POLYNOM;
else
crc = (crc >> 1);
}
}
i want to this code translate DELPHI.
please.
thanx
Start Value: 0xFFFF
CRC_POLYNOM = 0x8408;
CRC_PRESET = 0xFFFF;
C-Example:
unsigned internal CRC = CRC_PRESET;
for (i = 0; i < cnt; i++) /* cnt = number of protocol bytes without CRC */
{
crc ^= DATA[i];
for (j = 0; j < 8; j++)
{
if (crc & 0x0001)
crc = (crc >> 1) ^ CRC_POLYNOM;
else
crc = (crc >> 1);
}
}
i want to this code translate DELPHI.
please.
thanx
ASKER
After Translate (C2PAS) :
for (i := 0; i < cnt; i++) (* cnt = number of protocol bytes without CRC *)
begin
crc ^ := DATA[i];
for (j := 0; j < 8; j++)
begin
if (crc (* C2PAS: RefOrBit? *)& 0x0001) then
crc := (crc >> 1) ^ CRC_POLYNOM
else
crc := (crc >> 1);
end;
end;
what is this?? ( >> )
please (400 point :) ) i want to this code translatee..
for (i := 0; i < cnt; i++) (* cnt = number of protocol bytes without CRC *)
begin
crc ^ := DATA[i];
for (j := 0; j < 8; j++)
begin
if (crc (* C2PAS: RefOrBit? *)& 0x0001) then
crc := (crc >> 1) ^ CRC_POLYNOM
else
crc := (crc >> 1);
end;
end;
what is this?? ( >> )
please (400 point :) ) i want to this code translatee..
>> is a bitwise shift right operator shr is the pascal/delphi equivelent.
Sorry about that. :)
so >> should be replaced by shr
<< (if there were any) should be replaced by shl for a left shift
Sorry about that. :)
so >> should be replaced by shr
<< (if there were any) should be replaced by shl for a left shift
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Translated by OpenCtoPas (http://c2pas.sourceforge.net/)
unsigned internal CRC := CRC_PRESET;
for (i := 0; i < cnt; i++) (* cnt = number of protocol bytes without CRC *)
begin
crc ^ := DATA[i];
for (j := 0; j < 8; j++)
begin
if (crc or 0x0001) then
crc := (crc >> 1) ^ CRC_POLYNOM
else
crc := (crc >> 1);
end;
end;