本帖最后由 haogaoxiao 于 2010-09-15 11:52:46 编辑

解决方案 »

  1.   

    byte RedGetFc(string pack, uint len)
    {
        const ushort CRCNUM = 0xa001;
        byte test, crclow, crchigh, recode;
        uint j, crcnum = 0xffff, t;
        if (len == 0) return 0xFF;
        for (int i = 1; i <= len; i++)
        {
            test = (byte)pack[i - 1];
            crclow = (byte)crcnum;
            crchigh = (byte)(crcnum >> 8);
            crcnum = (uint)(test ^ crclow) + ((uint)crchigh) * 256;
            for (j = 1; j <= 8; j++)
            {
                t = crcnum & 0x0001;
                crcnum = crcnum >> 1;
                if (t != 0)
                {
                    crcnum = crcnum ^ CRCNUM;
                }
            }
        }
        recode = (byte)crcnum;
        return (recode);
    }
      

  2.   

    多谢wuyazhe,1楼的算法和我另外找的算法得到一样的结果
    用VIPY000007来计算,得到的 crcnum 都是 56859然后这样转换byte[] rebuf = BitConverter.GetBytes(crcnum);
    string Re = Convert.ToBase64String(rebuf);
    rebuf[0]=27,rebuf[1]=222
    1楼的算法得到的是27
    转换的Re="G94=" 
    算法估计没有错,但是不知道怎么转换得到校验码1D
    Encoding.Default.GetBytes("1D")得到buf[0]=49,buf[1]=68
      

  3.   

    string checksum = RedGetFc("VIPY000007",(uint)"VIPY000007".Length).ToString("X2");
    结果是1B