简单,多分,在线等!
char temp[8192];
int len=0;
unsigned short crc=0;
crc = cal_crc(0,temp,len);
code unsigned int crc16_table[256] = {
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0};
static unsigned short cal_crc(unsigned short s, unsigned char *ptr,
unsigned long len)
{
unsigned short crc;
unsigned char da;
crc = s;
while(len--!=0)
{
da = (unsigned char) (crc > > 8);
crc < <= 8;
crc ^= crc_ta[da^*ptr];
ptr++;
}
return (crc);
}
怎么把这个过程翻译为VB的啊?
[解决办法]
不懂,路过!
[解决办法]
什么语言啊,好像是C之类的东东。正打算学习。。
[解决办法]
网上有现成crc16的vb代码的,你可以搜索一下,我以前下载过
[解决办法]
前面一段是数组定义,比较简单,不翻译了,后面大概如下:
static unsigned short cal_crc(unsigned short s, unsigned char *ptr,
unsigned long len)
{
unsigned short crc;
unsigned char da;
crc = s;
while(len--!=0)
{
da = (unsigned char) (crc > > 8);
crc < <= 8;
crc ^= crc_ta[da^*ptr];
ptr++;
}
return (crc);
}
大概翻译如下(应该有错误,只是直接翻译的,没有经过DEBUG)
Private Declare Sub CopyMemory Lib "kernel32 " Alias "RtlMoveMemory " (pDest As Any, pSrc As Any, ByVal ByteLen As Long)
publisc function cal_crc(byval s as integer, buval ptr as long, byval len1 as long ) as inreger
dim crc as integer
dim da as string *1
dim tmp as string
crc=s
do while len1 <> 0
len1=len1-1
da=cint(crc/256)
crc=crc*256
copymemory tmp, ptr,8
crc= crc xor (da xor tmp)
ptr=ptr+2
loop
end function
[解决办法]
计算 CRC 的模块直接下一个,用不着自己翻译,编程要学会“偷懒”
[解决办法]
TO:wxf0204(网泥www.xmlenz.cn,QQ:21956798)
WallesCai(女人之美,在于蠢得无怨无悔,男人之美,在于撒谎撒得白日见鬼)没有错,
原函数为unsigned char *ptr,是指针,4字节,在VB中对应long型
[解决办法]
wxf0204(网泥www.xmlenz.cn,QQ:21956798)
楼上的老兄,
publisc function cal_crc(byval s as integer, buval ptr as long, byval len1 as long ) as inreger
这个地方定义有问题吧,ptr应该是string类型的吧
另外 ptr=ptr+2 这个地方不能这样吧
——————————————————————————
这个没有错,在C里面的指针在VB中只有用Long来模拟。
不过ptr=ptr+2确实和C代码中的ptr++不太对应,char类型的指针一次加一才对。
[解决办法]
http://www.mf100.com/document/2005-5/454.shtml
看看这个吧
[解决办法]
回头看了下,发现可能是关于指针的那段翻译错了,改成下面的试试
Private Declare Sub CopyMemory Lib "kernel32 " Alias "RtlMoveMemory " (pDest As Any, pSrc As Any, ByVal ByteLen As Long)
publisc function cal_crc(s as integer, ptr as long, len1 as long ) as inreger
dim crc as integer
dim da as string *1
dim tmp as string
crc=s
do while len1 <> 0
len1=len1-1
da=cint(crc/256)
crc=crc*256
copymemory tmp, byval ptr,8 '如果这个PTR传过来的是指针,这里应该是这样写
crc= crc xor crc_ta(da xor tmp)
ptr=ptr+2
loop
end function
[解决办法]
为你定制的,查表法来进行CRC32/CRC16的校验:
http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=12638&lngWId=1
[解决办法]
利用ASM,非常快!