CRC校验码的使用 既不清楚了,记得c做的时候是根据每个校验位进行操作,可能是&操作,结果赋给第16位校验的时候也是如此,看获得的结果和第16位的值是否相同 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.ilib.cn/A-yysfxyxb200404012.html using System;using System.Text;public sealed class CRC32{ public const int TABLE_SIZE = 256; public const uint STANDARD_POLYNOMIAL = 0xedb88320; private CRC32() { } static CRC32() { table = new uint[TABLE_SIZE]; polynomial = STANDARD_POLYNOMIAL; } public static bool Initialized { get { return initialized; } } [CLSCompliant(false)] public static uint Polynomial { get { return polynomial; } } private static uint[] table; private static uint polynomial; private static bool initialized; public static void Init(uint Polynomial) { polynomial = Polynomial; uint i = 0, j = 0; uint dwCRC = 0; for (i = 0; i < TABLE_SIZE; i++) { dwCRC = i; for (j = 8; j > 0; j--) { if ((dwCRC & 1) != 0) dwCRC = (dwCRC >> 1) ^ polynomial; else dwCRC >>= 1; } table[i] = dwCRC; } initialized = true; } public static void Init(int Polynomial) { byte[] intBytes = BitConverter.GetBytes(Polynomial); uint poly = BitConverter.ToUInt32(intBytes, 0); Init(poly); } public static void Init(long Polynomial) { const uint Mask = 0xffffffff; uint poly = (uint)(Polynomial & Mask); Init(poly); } public static void Init() { Init(STANDARD_POLYNOMIAL); } public static byte[] Crc32(byte[] data) { if (!initialized) throw new InvalidOperationException( "You must initialize the CRC table before attempting to calculate the check on data."); byte[] crc32_result; uint _result = 0, len = (uint)unchecked(data.Length); uint i = 0; const uint tableIndexMask = 0xff; uint dwCRC32 = 0xffffffff; for (i = 0; i < len; i++) { dwCRC32 = (dwCRC32 >> 8) ^ table[ (uint)data[i] ^ (dwCRC32 & tableIndexMask) ]; } _result = dwCRC32 ^ 0xffffffff; crc32_result = BitConverter.GetBytes(_result); return crc32_result; } public static unsafe byte[] Crc32(byte *pData, uint dwLength) { byte* ptr = pData; byte[] data = new byte[dwLength]; for (uint i = 0; i < dwLength; i++) { data[i] = *ptr; ptr++; } return Crc32(data); } public static byte[] Crc32(string data) { return Crc32(data, Encoding.ASCII); } public static byte[] Crc32(string data, Encoding encoding) { byte[] encData = encoding.GetBytes(data); return Crc32(encData); }} 能给一个数据吗,比如我byte[] crctest={1,0,0,1,0,1,0,1}这样用CRC算出来的校验码应是多少?我怎么才能确定算出来的数据是对的. byte[] crctest={1,0,0,1,0,1,0,1}-500323098(0xE22DACE6) // CRC3217117(0x42DD) // CRC16 计算结果和cangwu_lee(橙子)一致 C#大家看看我的委托的写法坐在那里 有奖哟! 朋友写的一个sys,在C#不会调用。。。 在线求助~!! Axis生成客户端访问代码 c#定时提醒问题 大家遇到这个错误吗? 欢迎收看明天的微软MSDN网络广播,了解最新的 Visual Basic 9.0 新特性! 如何让窗体像QQ一样,任务栏窗体闪烁 高手們快來看啊!這樣的dataSet如何填充數據? (重賞﹗﹗﹗) 救命!iis突然出错!! 关于想创建一个公用的数据库连接操作的类的问题 C#多线程的问题?
using System.Text;public sealed class CRC32
{
public const int TABLE_SIZE = 256; public const uint STANDARD_POLYNOMIAL = 0xedb88320; private CRC32()
{
} static CRC32()
{
table = new uint[TABLE_SIZE];
polynomial = STANDARD_POLYNOMIAL;
} public static bool Initialized
{
get { return initialized; }
}
[CLSCompliant(false)]
public static uint Polynomial
{
get { return polynomial; }
} private static uint[] table;
private static uint polynomial;
private static bool initialized;
public static void Init(uint Polynomial)
{
polynomial = Polynomial;
uint i = 0, j = 0;
uint dwCRC = 0; for (i = 0; i < TABLE_SIZE; i++)
{
dwCRC = i;
for (j = 8; j > 0; j--)
{
if ((dwCRC & 1) != 0)
dwCRC = (dwCRC >> 1) ^ polynomial;
else
dwCRC >>= 1;
}
table[i] = dwCRC;
} initialized = true;
} public static void Init(int Polynomial)
{
byte[] intBytes = BitConverter.GetBytes(Polynomial);
uint poly = BitConverter.ToUInt32(intBytes, 0);
Init(poly);
} public static void Init(long Polynomial)
{
const uint Mask = 0xffffffff;
uint poly = (uint)(Polynomial & Mask);
Init(poly);
} public static void Init()
{
Init(STANDARD_POLYNOMIAL);
} public static byte[] Crc32(byte[] data)
{
if (!initialized)
throw new InvalidOperationException(
"You must initialize the CRC table before attempting to calculate the check on data."); byte[] crc32_result;
uint _result = 0, len = (uint)unchecked(data.Length);
uint i = 0; const uint tableIndexMask = 0xff; uint dwCRC32 = 0xffffffff;
for (i = 0; i < len; i++)
{
dwCRC32 = (dwCRC32 >> 8) ^ table[ (uint)data[i] ^ (dwCRC32 & tableIndexMask) ];
} _result = dwCRC32 ^ 0xffffffff; crc32_result = BitConverter.GetBytes(_result);
return crc32_result;
} public static unsafe byte[] Crc32(byte *pData, uint dwLength)
{
byte* ptr = pData;
byte[] data = new byte[dwLength];
for (uint i = 0; i < dwLength; i++)
{
data[i] = *ptr;
ptr++;
} return Crc32(data);
} public static byte[] Crc32(string data)
{
return Crc32(data, Encoding.ASCII);
} public static byte[] Crc32(string data, Encoding encoding)
{
byte[] encData = encoding.GetBytes(data);
return Crc32(encData);
}
}
我怎么才能确定算出来的数据是对的.
17117(0x42DD) // CRC16