Sys(2007) in c#

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

I am stuck at this line of code

SYS(2007,ALLTRIM(clipmade.rcompany))

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

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

x
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.

MajorBigDealCommented:
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.

http://www.codeproject.com/KB/cs/marcelcrcencoding.aspx

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())
0

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);
crc.ComputeChecksum(((Bytes)(clipmade.rcompany).Trim()));

Open in new window


regards
0
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:
http://msdn.microsoft.com/en-us/library/74zkxe2k%28VS.80%29.aspx

Sys() function for example here:
http://msdn.microsoft.com/en-us/library/65zx7k19%28VS.80%29.aspx

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: http://vfpx.codeplex.com/releases/view/23319

Besides this, there is a toolkit implementing some foxpro functions, that also could help you keep it compatible on those: http://foxcentral.net/microsoft/vfptoolkitnet.htm

Bye, Olaf.
0
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
FoxPro

From novice to tech pro — start learning today.