下面代码用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);
}

解决方案 »

  1.   

    下面代码用java怎么实现 
     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); 

      

  2.   

    int CalCrc(char[] buffer) { 
        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);