请问这段JAVA代码如何转换成C++代码?

kuohai123 2010-06-09 09:00:10

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数组,就会出错,谢谢先~
...全文
120 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
tommy_mq 2010-06-09
  • 打赏
  • 举报
回复
都可以的
East271536394 2010-06-09
  • 打赏
  • 举报
回复
最简单的方法,,将java 转成0101 这类东西,在将00101 转成c

呵,


开个玩笑,用JNI 吧。。
kuohai123 2010-06-09
  • 打赏
  • 举报
回复
谢谢4楼的兄弟,byte类型可以转换成int类型吗?两者有什么区别啊~!
  • 打赏
  • 举报
回复
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;
}
ptcoding 2010-06-09
  • 打赏
  • 举报
回复
byte就是unsigned char
kuohai123 2010-06-09
  • 打赏
  • 举报
回复
BYTE 数组不行吗?
friendly_ 2010-06-09
  • 打赏
  • 举报
回复
char 数组

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧