How do I implement a CRC16 with a custom polynomial in Javascript?

时光总嘲笑我的痴心妄想 提交于 2020-02-16 06:37:23

问题


Background

I need to implement a CRC16 with a custom polynomial in Javascript.

Research

After searching several NPM modules and this SO question ( as well as all the links the comments suggest ):

  • Javascript CRC16 sample code or implementation
  • https://github.com/donvercety/node-crc16

I am still not any closer to my goal.

Problem

My problem is that even though I have the code, I can't understand how to re-use a given CRC16 solution because I don't know where to find the polynomial definition in the code. With all the shifts and whatnot it's just too cryptic for me.

Question

How can I have a CRC16 function with a custom polynomial ?


回答1:


The example linked has a table derived from the CRC polynomial. You can certainly find code that generates the table, given the polynomial. You can find code that computes any CRC, and code that generates CRC code, including the table, given the definition of the CRC (polynomial, bit-ordering, initial value, final xor value).



来源:https://stackoverflow.com/questions/50026573/how-do-i-implement-a-crc16-with-a-custom-polynomial-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!