Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# version of sys(2007)
Message
From
17/07/2014 18:12:15
 
 
To
17/07/2014 15:42:58
General information
Forum:
Visual FoxPro
Category:
Visual FoxPro and .NET
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows 7
Network:
SAMBA Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01603907
Message ID:
01603970
Views:
43
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
}
Previous
Reply
Map
View

Click here to load this message in the networking platform