Click here to Skip to main content
15,890,579 members

Comments by Member 14827175 (Top 18 by date)

Member 14827175 1-Mar-21 18:37pm View    
Deleted
This might be old, but doesn't this do the Kermit method?
I tried it and was getting reversed bytes (when compared to known good XMODEM calculator). I ended up doing:

private byte[] Crc16ccitt(byte[] bytes)
{
const ushort poly = 4129;
ushort[] table = new ushort[256];
ushort initialValue = 0;
ushort temp, a;
ushort crc = initialValue;
for (int i = 0; i < table.Length; ++i)
{
temp = 0;
a = (ushort)(i << 8);
for (int j = 0; j < 8; ++j)
{
if (((temp ^ a) & 0x8000) != 0)
temp = (ushort)((temp << 1) ^ poly);
else
temp <<= 1;
a <<= 1;
}
table[i] = temp;
}
for (int i = 0; i < bytes.Length; ++i)
{
crc = (ushort)((crc << 8) ^ table[((crc >> 8) ^ (0xff & bytes[i]))]);
}
byte[] _crc = BitConverter.GetBytes(crc);
Array.Reverse(_crc);
return (_crc);
}
Member 14827175 1-Mar-21 18:36pm View    
Deleted
This might be old, but doesn't this do the Kermit method?
I tried this and was getting reversed bytes (when compared to known good XMODEM calculator). I ended up doing:

private byte[] Crc16ccitt(byte[] bytes)
{
const ushort poly = 4129;
ushort[] table = new ushort[256];
ushort initialValue = 0;
ushort temp, a;
ushort crc = initialValue;
for (int i = 0; i < table.Length; ++i)
{
temp = 0;
a = (ushort)(i << 8);
for (int j = 0; j < 8; ++j)
{
if (((temp ^ a) & 0x8000) != 0)
temp = (ushort)((temp << 1) ^ poly);
else
temp <<= 1;
a <<= 1;
}
table[i] = temp;
}
for (int i = 0; i < bytes.Length; ++i)
{
crc = (ushort)((crc << 8) ^ table[((crc >> 8) ^ (0xff & bytes[i]))]);
}
byte[] _crc = BitConverter.GetBytes(crc);
Array.Reverse(_crc);
return (_crc);
}
Member 14827175 27-Feb-21 11:48am View    
Good suggestion, just checked the length, it's as expected - 530. But with each iteration it doubles, should I be flushing/clearing it in someway?
Member 14827175 27-Feb-21 11:19am View    
OK, I'll update my question with some more details, thanks. And your English is perfectly splendid ;)
Member 14827175 27-Feb-21 11:19am View    
Deleted
OK, I'll update my question with some more details, thanks. And your English is perfectly splendid ;)