最终CRC对C [英] definitive CRC for C

查看:197
本文介绍了最终CRC对C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于CRC的用途很广泛,我对有一个很难找到CRC实现在C吃惊

Since CRC is so widely used, I'm surprised by having a hard time finding CRC implementations in C.

有一个明确的CRC计算片段/对于C算法,即每个人使用?或者:有没有一个很好的实现CRC人可以担保,并指出我推向?我在寻找特别CRC8和CRC16实现。

Is there a "definitive" CRC calculation snippet/algorithm for C, that "everyone" uses? Or: is there a good CRC implementation somebody can vouch for, and point me towards? I'm looking for CRC8 and CRC16 implementations in particular.

试想想起来了,我的情况可能会有点标新立异。我正在写C code代表的Linux,和code应最终被移植到微控制器。这似乎有些微的API做出来的CRC的实现;在任何情况下,我在寻找一个通用的软件实现(我读了CRC最初意思是硬件实现)。

Come to think of it, my situation may be a little unconventional. I'm writing C code for Linux, and the code should eventually be ported to a microcontroller. It seems some microcontroller APIs do come with CRC implementations; in any case, I'm looking for a generic software implementation (I read that CRC is originally meant to be hardware implemented).

推荐答案

没有。没有明确的CRC为CRC重新presents一套基于多项式算法。各种[暧昧]通用名称是基于大小通常给定(例如CRC-8,CRC-32)。不幸的是,有几种不同的版本为大多数尺寸

No. There is no "definitive CRC" as CRC represents a set of algorithms based upon polynomials. Various [ambiguous] common names are usually given based on size (e.g. CRC-8, CRC-32). Unfortunately, there are several different versions for most sizes.

维基百科的<一个href=\"http://en.wikipedia.org/wiki/Cyclic_redundancy_check#Commonly_used_and_standardized_CRCs\">Cyclic冗余校验作品列出了一些常见的变体,但是的正确的校验的的的定域的必须使用,否则会出现不兼容问题。 (见我对迈克的回答只是评论如何混乱这个可以有!)

Wikipedia's Cyclic Redundancy Check entry lists some common variants, but the correct checksum for the given domain must be used or else there will be incompatibilities. (See my comment to Mike's answer for just how confusing this can be!)

总之,挑一个合适的实现,使用它 - 没有,可以在网上找到例子举不胜举。如果恰好是提供一个合适的实现,那么图书馆,通过各种手段,使用它。然而,不存在标准C库这一点。

Anyway, pick a suitable implementation and use it - there is no shortage of examples that can be found online. If there happens to be a library that provides a suitable implementation then, by all means, use that. However, there is no "standard" C library for this.

下面是一些资源:

  • A "CRC16" (CRC-16-CCITT) implementation on AutomationWiki.
  • Implementing The CCITT Cyclical Redundancy Check on Dr Dobbs.
  • The IEEE 802.3 Cyclic Redundancy Check article by Chris Borrelli discusses an obsolete Xilinx tool to generate Verilog (i.e. "to hardware") implementations.
  • See associated question CRC32 C or C++ implementation - note that some answers relate to "CRC32" (IEEE 802.3) and others to Adler-32.
  • The librock library, boost, source for cksum from GNU core utils ..

这篇关于最终CRC对C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆