首页 > 其他 > 详细

CRC

时间:2018-06-14 13:32:11      阅读:224      评论:0      收藏:0      [点我收藏+]

CRC 在线工具:http://www.ip33.com/crc.html

 

1.CRC16_XMODEM  x16+x12+x5+1

  多项式:1021

   初始值:0000

 C#

   

 public static int CRC16_XMODEM(byte[] datas)
        {
            int crc = 0x0000;//初始值
            int crcPoly = 0x1021;
            for(int i=0;i<datas.Length;i++)
            {       
                crc ^= (datas[i] << 8);            

                for(int j=0;j<8;j++)
                {                  
                  
                    if ((crc & 0x8000)>0)
                    {                      
                        crc = (ushort)((crc << 1) ^ crcPoly);
                    }
                    else
                    {                      
                        crc = (ushort)(crc << 1);
                    }
                }
            }
            return crc;
        }

c++

uint16_t MainWindow::crc16_xmodem(uint8_t *data, int length)
{
   uint8_t i;
   uint16_t crc = 0;       // Initial value
   while(length--)
   {
       crc ^= (uint16_t)(*data++) << 8; // crc ^= (uint16_t)(*data)<<8; data++;for (i = 0; i < 8; ++i)
        {
            if ( crc & 0x8000 )
            {              
               crc = (crc << 1) ^ 0x1021;
            }
            else
            {            
                crc <<= 1;
            }
       }
    }
    return crc;
}

 

  

CRC

原文:https://www.cnblogs.com/ike_li/p/9182002.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!