您的位置:

crc8的js实现(crc8代码)

crc8的js实现(crc8代码)

更新:

本文目录一览:

求并行 CRC8 的 verilog 代码,多项式为 X8+X5+X4+X3+1(0x39)

在线生成工具

这个生成的是function,不可综合的。自己改成module就行了

////////////////////////////////////////////////////////////////////////////////

// Copyright (C) 1999-2008 Easics NV.

// This source file may be used and distributed without restriction

// provided that this copyright statement is not removed from the file

// and that any derivative work contains the original copyright notice

// and the associated disclaimer.

//

// THIS SOURCE FILE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS

// OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED

// WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

//

// Purpose : synthesizable CRC function

// * polynomial: (0 3 4 5 8)

// * data width: 8

//

// Info : tools@easics.be

//

////////////////////////////////////////////////////////////////////////////////

module CRC8_D8;

// polynomial: (0 3 4 5 8)

// data width: 8

// convention: the first serial bit is D[7]

function [7:0] nextCRC8_D8;

input [7:0] Data;

input [7:0] crc;

reg [7:0] d;

reg [7:0] c;

reg [7:0] newcrc;

begin

d = Data;

c = crc;

newcrc[0] = d[6] ^ d[5] ^ d[4] ^ d[3] ^ d[0] ^ c[0] ^ c[3] ^ c[4] ^ c[5] ^ c[6];

newcrc[1] = d[7] ^ d[6] ^ d[5] ^ d[4] ^ d[1] ^ c[1] ^ c[4] ^ c[5] ^ c[6] ^ c[7];

newcrc[2] = d[7] ^ d[6] ^ d[5] ^ d[2] ^ c[2] ^ c[5] ^ c[6] ^ c[7];

newcrc[3] = d[7] ^ d[5] ^ d[4] ^ d[0] ^ c[0] ^ c[4] ^ c[5] ^ c[7];

newcrc[4] = d[4] ^ d[3] ^ d[1] ^ d[0] ^ c[0] ^ c[1] ^ c[3] ^ c[4];

newcrc[5] = d[6] ^ d[3] ^ d[2] ^ d[1] ^ d[0] ^ c[0] ^ c[1] ^ c[2] ^ c[3] ^ c[6];

newcrc[6] = d[7] ^ d[4] ^ d[3] ^ d[2] ^ d[1] ^ c[1] ^ c[2] ^ c[3] ^ c[4] ^ c[7];

newcrc[7] = d[5] ^ d[4] ^ d[3] ^ d[2] ^ c[2] ^ c[3] ^ c[4] ^ c[5];

nextCRC8_D8 = newcrc;

end

endfunction

endmodule

用C语言编写,crc8校验9个字节的数据,生成多项式为x8+x2+x+1,

// 8bit CRC (X(8) + X(2) + X(1) + 1)

typedef unsigned long  DWORD;

typedef unsigned short WORD;

typedef unsigned char  BYTE;

#define AL2_FCS_COEF ((1  7) + (1  6) + (1  5))

//data为指向校验数据的指针,length为长度,返回一个字节的校验码

BYTE GetCrc8(unsigned char * data, int length)

{

   BYTE cFcs = 0;

   int i, j;

   for( i = 0; i  length; i ++ )

   {

      cFcs ^= data[i];

      for(j = 0; j  8; j ++)

      {

         if(cFcs  1)

         {

            cFcs = (BYTE)((cFcs  1) ^ AL2_FCS_COEF);

         }

         else

         {

            cFcs = 1;

         }

      }

   }

   return cFcs;

}

CRC校验的算法有几种?

具体的找些参考资料吧,一两句话也说不清楚

;hl=zh-CNct=clnkcd=1gl=cnst_usg=ALhdy2_AJ0YjhnCWFMb5xtYPvXTzPgd_2Q

下面的还有程序实现:

如何用java实现CRC8验证算法

/*

*---------------------------------------------------------------------------

* Copyright (C) 1999,2000 Dallas Semiconductor Corporation, All Rights Reserved.

*

* Permission is hereby granted, free of charge, to any person obtaining a

* copy of this software and associated documentation files (the "Software"),

* to deal in the Software without restriction, including without limitation

* the rights to use, copy, modify, merge, publish, distribute, sublicense,

* and/or sell copies of the Software, and to permit persons to whom the

* Software is furnished to do so, subject to the following conditions:

*

* The above copyright notice and this permission notice shall be included

* in all copies or substantial portions of the Software.

*

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS

* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.

* IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES

* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,

* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR

* OTHER DEALINGS IN THE SOFTWARE.

*

* Except as contained in this notice, the name of Dallas Semiconductor

* shall not be used except as stated in the Dallas Semiconductor

* Branding Policy.

*---------------------------------------------------------------------------

*/

package com.dalsemi.onewire.utils;

/**

* CRC8 is a class to contain an implementation of the

* Cyclic-Redundency-Check CRC8 for the iButton. The CRC8 is used

* in the 1-Wire Network address of all iButtons and 1-Wire

* devices.

* p

* CRC8 is based on the polynomial = X^8 + X^5 + X^4 + 1.

*

* @version 0.00, 28 Aug 2000

* @author DS

*

*/

public class CRC8

{

//--------

//-------- Variables

//--------

/**

* CRC 8 lookup table

*/

private static byte dscrc_table [];

/*

* Create the lookup table

*/

static

{

//Translated from the assembly code in iButton Standards, page 129.

dscrc_table = new byte [256];

int acc;

int crc;

for (int i = 0; i 256; i++)

{

acc = i;

crc = 0;

for (int j = 0; j 8; j++)

{

if (((acc ^ crc) 0x01) == 0x01)

{

crc = ((crc ^ 0x18) 1) | 0x80;

}

else

crc = crc 1;

acc = acc 1;

}

dscrc_table [i] = ( byte ) crc;

}

}

//--------

//-------- Constructor

//--------

/**

* Private constructor to prevent instantiation.

*/

private CRC8 ()

{

}

//--------

//-------- Methods

//--------

/**

* Perform the CRC8 on the data element based on the provided seed.

* p

* CRC8 is based on the polynomial = X^8 + X^5 + X^4 + 1.

*

* @param dataToCrc data element on which to perform the CRC8

* @param seed seed the CRC8 with this value

* @return CRC8 value

*/

public static int compute (int dataToCRC, int seed)

{

return (dscrc_table [(seed ^ dataToCRC) 0x0FF] 0x0FF);

}

/**

* Perform the CRC8 on the data element based on a zero seed.

* p

* CRC8 is based on the polynomial = X^8 + X^5 + X^4 + 1.

*

* @param dataToCrc data element on which to perform the CRC8

* @return CRC8 value

*/

public static int compute (int dataToCRC)

{

return (dscrc_table [dataToCRC 0x0FF] 0x0FF);

}

/**

* Perform the CRC8 on an array of data elements based on a

* zero seed.

* p

* CRC8 is based on the polynomial = X^8 + X^5 + X^4 + 1.

*

* @param dataToCrc array of data elements on which to perform the CRC8

* @return CRC8 value

*/

public static int compute (byte dataToCrc [])

{

return compute(dataToCrc, 0, dataToCrc.length);

}

/**

* Perform the CRC8 on an array of data elements based on a

* zero seed.

* p

* CRC8 is based on the polynomial = X^8 + X^5 + X^4 + 1.

*

* @param dataToCrc array of data elements on which to perform the CRC8

* @param off offset into array

* @param len length of data to crc

* @return CRC8 value

*/

public static int compute (byte dataToCrc [], int off, int len)

{

return compute(dataToCrc, off, len, 0);

}

/**

* Perform the CRC8 on an array of data elements based on the

* provided seed.

* p

* CRC8 is based on the polynomial = X^8 + X^5 + X^4 + 1.

*

* @param dataToCrc array of data elements on which to perform the CRC8

* @param off offset into array

* @param len length of data to crc

* @param seed seed to use for CRC8

* @return CRC8 value

*/

public static int compute (byte dataToCrc [], int off, int len, int seed)

{

// loop to do the crc on each data element

int CRC8 = seed;

for (int i = 0; i len; i++)

CRC8 = dscrc_table [(CRC8 ^ dataToCrc [i + off]) 0x0FF];

return (CRC8 0x0FF);

}

/**

* Perform the CRC8 on an array of data elements based on the

* provided seed.

* p

* CRC8 is based on the polynomial = X^8 + X^5 + X^4 + 1.

*

* @param dataToCrc array of data elements on which to perform the CRC8

* @param seed seed to use for CRC8

* @return CRC8 value

*/

public static int compute (byte dataToCrc [], int seed)

{

return compute(dataToCrc, 0, dataToCrc.length, seed);

}

}

CAN总线通信里的这个字符的CRC运算是CRC8,还是CRC16还是CRC32运算?

CAN总线的CRC场共16bit,其中最后1bit为CRC序列后随的CRC界定符仅由单个“隐性”位构成。所以用于CRC校验的是15bit即CRC15。用于帧校验的CRC序列由特别适用于位数小于127位帧的循环冗余码校验(BCH码)驱动。为实现CRC计算,被除的多项式被定义为这样一个多项式,其系数由帧起始、仲裁场、控制场、数据场(如果存在)和15位最低系数为0组成的解除填充的位流给定。此多项式被下列生成多项式

X15+X14+X10+X8+X7+X4+X3+1

除(系数按模-2计算),该多项式相除的余数即为发至总线的CRC序列。

为实现这一功能,可以使用15位移位寄存器CRC-RG(14:0)。若NXTBIT标示由帧起始直至数据场结束的解除填充位序列给定位流的下一位,则CRC序列计算如下:

CRC—RG(14:0)=(0); //初始化移位寄存器

REPEAT

CRCNXT=NXTBIT EXOR CRC—RG(14);

CRC—RG(14:1)= CRC—RG(13:0); //左移一位

CRC—RG(0)=0;

IF CRCNXT THEN

CRC—RG(14:0)=CRC—RG(14:0)EXOR(4599H);

END IF

UNTIL(NXTBIT=数据结束或存在一个错误条件)。

数据场最后一位发送/接收后,CRC—RG中含有CRC序列。CRC序列后随的CRC界定符仅由单个“隐性”位构成。

nodejs 怎么执行 crc32

const crc=require('node-crc');

var result = crc.crc32(Buffer.from('hello', 'utf8')).toString('hex');

var result2 = crc.crc64(Buffer.from('world', 'utf8')).toString('hex');

链接在这里:网页链接

你品,你细品

crc8的js实现(crc8代码)

本文目录一览: 1、求并行 CRC8 的 verilog 代码,多项式为 X8+X5+X4+X3+1(0x39) 2、用C语言编写,crc8校验9个字节的数据,生成多项式为x8+x2+x+1, 3、C

2023-12-08
CRC8校验算法C语言

2023-05-20
CRC8算法详解

2023-05-20
javacrc,javacrc校验

2022-11-27
求php下crc( php)

2022-11-08
htmljs编程笔记(html代码笔记)

本文目录一览: 1、html代码和JS代码有什么区别 2、如何在html中调用js函数 3、JavaScript学习笔记之数组基本操作示例 4、HTML5初学者笔记 5、《web前端笔记7》js字符—

2023-12-08
js高级程序设计笔记14(js高级程序设计笔记14页)

本文目录一览: 1、JavaScript高级程序设计 该怎么看 2、JavaScript学习笔记之数组基本操作示例 3、JS中有关sort以及return的问题 JavaScript高级程序设计 该怎

2023-12-08
js代码中script,js代码中的问号是什么意思

本文目录一览: 1、javascript中script的SRC属性 2、JS代码里加载script代码,并隐藏其内容怎么弄呢? 3、使用javascript必须使script标签吗 javascrip

2023-12-08
javascript简要笔记,JavaScript读书笔记

2022-11-17
重学java笔记,java笔记总结

2022-11-23
js代码总结体会,js基础知识总结笔记

本文目录一览: 1、js到底难不难学? 2、JS 代码 求解释 可以详细的 说明一下 谢谢 3、浅谈js写轮播图的思路与心得 4、JavaScript与WEB前台开发课程实训总结怎么写 5、js中继承

2023-12-08
js代码整洁随笔,js代码整理

本文目录一览: 1、如何在页面让JavaScript代码原样显示,用标签不起用,js照常运行。请看问题补充 2、怎么让JS文件代码对齐 3、怎么样格式化javascript,怎么样格式化js 4、为什

2023-12-08
java学习笔记(java初学笔记)

2022-11-14
javascript一句话笔记,javascript基本语句

2022-11-16
用js实现des代码(DES算法的实现代码)

本文目录一览: 1、请教老师DES和DES3的加解密的JS代码 2、python中如何调用js文件中的方法呢 3、为什么 CryptoJS DES 加密的结果和 Java DES 不一样 4、关于no

2023-12-08
java笔记,大学java笔记

2022-11-28
jsp上一条记录代码,jsp上一条记录代码不见了

本文目录一览: 1、上一页12345下一页这样的JSP代码怎么实现 2、有关向数据库中添加一条记录的问题,JSP代码 3、请问:关于jsp中的一小段代码 上一页12345下一页这样的JSP代码怎么实现

2023-12-08
java笔记,尚硅谷java笔记

2022-12-01
java调用js代码,java调用js代码 实例

本文目录一览: 1、如何在java中调用js方法 2、如何通过java代码调用js 3、java中怎么调用js代码 4、如何在java调用js 5、请问怎么写java调用node环境运行js代码? 如

2023-12-08
代码之神js实战,狂神javascript笔记

2022-11-25