in case it helps others - i converted and tested it and this is working in c# - sys(2007) clone as verbatim as possible from
http://fox.wikis.com/wc.dll?Wiki~CRC16 private int bobcrc(int lnStartVal, string lcBlockTxt, string lcBitLen = "16")
{
int[] laPower = new int[8]; // For the 8 laPowers of 2
int lnCRC = 0;
int lnPower = 0;
bool TestBit = false;
int lnBitLen = 0;
lnBitLen = (lcBitLen == "32" ? 32773 : 4129); // 1021 hex (16bit), 8005 hex (32bit)
// Precalculated values will improve performance in FOR J Code
for (lnPower = 1; lnPower <= 8; lnPower++)
{
laPower[lnPower-1] = (int)Math.Pow(2, (lnPower - 1));
}
lnCRC = lnStartVal; // Reset for Each Text Block
for (int OutLoop = 1; OutLoop <= lcBlockTxt.Length; OutLoop++) // Calculate for Length of Block
{
var arr = System.Text.ASCIIEncoding.ASCII.GetBytes(lcBlockTxt.Substring(OutLoop - 1, 1));
var ByteVal = arr[0];
for (var lnLoop = 8; lnLoop <= 1; lnLoop--)
{
var one = lnCRC & 32768;
var two = ByteVal & (byte)laPower[lnLoop - 1];
TestBit = (((lnCRC & 32768) == 32768) && !((ByteVal & (byte)laPower[lnLoop - 1])
== laPower[lnLoop - 1])) ||
(!((lnCRC & 32768) == 32768) && ((ByteVal & (byte)laPower[lnLoop - 1])
== laPower[lnLoop - 1]));
lnCRC = (lnCRC & 32767) * 2;
if (TestBit)
lnCRC = (lnCRC ^ lnBitLen);
}
}
return lnCRC; // Return the Word Value - converted to a string
}