String getCRC(byte[] arg) {
int i, accumulator, data, index;
String returnValue = new String();
accumulator = 0xffff;
for (i=0; i<arg.length; i++) {
data = arg[i];
index = (accumulator >> 8) ^ data;
accumulator = (accumulator << 8) ^ this.crcTable[index];
}
accumulator ^= 0xffff;
returnValue = Integer.toHexString(accumulator).toUpperCase();
for (i=returnValue.length(); i<4; i++)
returnValue = '0' + returnValue;
return returnValue;
}转换成C++的代码不是到byte[]数组应该替换成什么数组,如果替换成BYTE数组,就会出错,谢谢先~

解决方案 »

  1.   

    char getCRC(int arg[])
    {
    int i, accumulator, data, index,n=0;//n为数组arg
    string returnValue;
    accumulator=-1;//0xffff=-1
    for(int i=0;i<n;i++)
    {
    data=arg[i];
    index = (accumulator >> 8) ^ data;
    accumulator = (accumulator << 8) ^ this.crcTable[index];//不知道楼主这个代码是一个类里面的么?
    }
    accumulator ^=1;
    returnValue =accumulator;//C++好像没这个函数能忽略大小写
    for (i=n; i<4; i++)、、
    returnValue = '0' + returnValue;
    return returnValue;
    }
      

  2.   

    谢谢4楼的兄弟,byte类型可以转换成int类型吗?两者有什么区别啊~!
      

  3.   

    最简单的方法,,将java  转成0101 这类东西,在将00101 转成c呵,
    开个玩笑,用JNI 吧。。