下面代码用java怎么实现
unsigned int CalCrc(char * buffer,unsigned int count)
{
unsigned int i,j;
unsigned int CrcValue = 0;
for(i=0;i<count;i++)
{
CrcValue = CrcValue ^ ( buffer[i] << 8 ); for (j = 0; j < 8; j++)
if (CrcValue & 0x8000)
CrcValue = (CrcValue << 1) ^ 0x1021;
else
CrcValue = CrcValue << 1;
}
return (CrcValue);
}
unsigned int CalCrc(char * buffer,unsigned int count)
{
unsigned int i,j;
unsigned int CrcValue = 0;
for(i=0;i<count;i++)
{
CrcValue = CrcValue ^ ( buffer[i] << 8 ); for (j = 0; j < 8; j++)
if (CrcValue & 0x8000)
CrcValue = (CrcValue << 1) ^ 0x1021;
else
CrcValue = CrcValue << 1;
}
return (CrcValue);
}
解决方案 »
- 大家说说精通一门语言那需要多久
- 对象流的问题
- 急!!关于Java写的PL0编译器两个问题
- 寒假想学struts和Hibernate,请大家推荐基本好书
- 为什么覆盖方法时,不能使用比父类中被覆盖的方法更严格的访问权限?
- 怎样学习java的包???
- 按行读-写文件有错误。奇怪的问题,200分请教!
- UltraEdit和Jcreator编程时回车后大刮号“{ }”呈阶梯状,怎么样设置能在回车后“{ }”直接对齐?
- Jbuilder6那里可以down???
- 我在红帽Linux下用rpm -i j2sdk-1_3_0-linux.rpm安装了jdk1.3,java装载到了/usr/java下,接下来我该how to do?
- 文件输出时,多了几个方块,奇怪,大家帮忙~~~
- 急~~~~现等高手解决
int CalCrc(char[] buffer, int count) {
int i,j;
int CrcValue = 0;
for(i=0;i <count;i++){
CrcValue = CrcValue ^( buffer[i] < < 8 ); for (j = 0; j < 8; j++)
if (CrcValue & 0x8000) {
CrcValue = (CrcValue < < 1) ^ 0x1021;
}else{
CrcValue = CrcValue < < 1;
}
}
return (CrcValue);
}
int i,j;
int CrcValue = 0;
for(i=0;i <buffer.length;i++){
CrcValue = CrcValue ^( buffer[i] < < 8 ); for (j = 0; j < 8; j++)
if (CrcValue & 0x8000) {
CrcValue = (CrcValue < < 1) ^ 0x1021;
}else{
CrcValue = CrcValue < < 1;
}
}
return (CrcValue);
}