Sys(2007) in c#

I have a foxpro code which I need to convert into c#.

I am stuck at this line of code


could any one help me in coverting this to c# code
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Code 2007 is CRC32 checksum.

I googled it and was disappointed to find that C# doesn't have a built in method for this.  However if you google "c# crc32", you will get a ton of hits on various ways of implementing in c#.   Here is an example that is highly-rated (over 4 stars) but there are lots of others as well.

ALLTRIM is the same as C# Trim();

So, using the example implementation in the above link, and assuming clipmade.rcompany is a string: compCRC.crctablefast(clipmade.rcompany.Trim())

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nishant joshiTechnology Development ConsultantCommented:
add this class to your project..
using System;

public enum InitialCrcValue { Zeros, NonZero1 = 0xffff, NonZero2 = 0x1D0F }

public class Crc16Ccitt {
    const ushort poly = 4129;
    ushort[] table = new ushort[256];
    ushort initialValue = 0;

    public ushort ComputeChecksum(byte[] bytes) {
        ushort crc = this.initialValue;
        for(int i = 0; i < bytes.Length; ++i) {
            crc = (ushort)((crc << 8) ^ table[((crc >> 8) ^ (0xff & bytes[i]))]);
        return crc;

    public byte[] ComputeChecksumBytes(byte[] bytes) {
        ushort crc = ComputeChecksum(bytes);
        return BitConverter.GetBytes(crc);

    public Crc16Ccitt(InitialCrcValue initialValue) {
        this.initialValue = (ushort)initialValue;
        ushort temp, a;
        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;

Open in new window

and then your c# code will be..
Crc16Ccitt crc=new Crc16Ccitt(InitialCrcValue.NonZero2);

Open in new window

Olaf DoschkeSoftware DeveloperCommented:
Crc16citt instead of CRC32? Sure? Actually you are right, because only if a fourth, optional parameter would be 1, sys(2007) would compute CRC32, as it's not, SYS(2700,string) computes CRC16 of the string.

Also note, Sys(2700) returns a string! Even though CRC16 computes a number, this is returned as a string. So for compatibility you'd need to convert the result .ToString().

To give you some examples for testing the implementation:
sys(2700,"abc") -> "20810"
sys(2700,"xyz") -> "53289"
sys(2700,"ziorinfo") -> "23948"

See if you get those exact numbers from Crc16Ccitt.
Depending on the usage of the checksum you may replac eit with a total different checksum mechanism, and eg recompute all currently stored checksums.

As a much more general help, the reference on VFP commands and functions is online at MSDN:

Sys() function for example here:

Actually the Sys() functions are functions, that didn't make it into getting a real function name. Some nevertheless have, eg SYS(0) is also ID(). But that's just a side note.

You also can get the full help as a chm, as it's been given to the fox community under a codeplex shared source license:

Besides this, there is a toolkit implementing some foxpro functions, that also could help you keep it compatible on those:

Bye, Olaf.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.