⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ccitt crc16 code.htm

📁 CRC16的源程序
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0045)http://www.eagleairaust.com.au/code/crc16.htm -->
<HTML><HEAD><TITLE>CCITT CRC16 Code</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 6.00.2800.1106" name=GENERATOR>
<META content=FrontPage.Editor.Document name=ProgId></HEAD>
<BODY>
<H5 align=center>Bored with this page? Click <A 
href="http://www.eagleairaust.com.au/code/welcome.htm">here</A> to return to 
main index.</H5>
<CENTER>
<P>
<HR align=center>

<P></P></CENTER>
<P align=center><FONT size=7>S</FONT><FONT size=5>ample </FONT><FONT 
size=7>CCITT CRC</FONT><FONT size=5> </FONT><FONT size=7>C</FONT><FONT 
size=5>ode</FONT></P>
<CENTER>
<P>
<HR align=center>
</CENTER><PRE><FONT color=#ff0000>// Update the CRC for transmitted and received data using
// the CCITT 16bit algorithm (X^16 + X^12 + X^5 + 1).</FONT>

    <B>unsigned</B> <B>char</B> ser_data;
    <B>static unsigned</B> <B>int</B> crc;

    crc  = (<B>unsigned char</B>)(crc &gt;&gt; <FONT color=#0000ff>8</FONT>) | (crc &lt;&lt; <FONT color=#0000ff>8</FONT>);
    crc ^= ser_data;
    crc ^= (<B>unsigned char</B>)(crc &amp; <FONT color=#0000ff>0xff</FONT>) &gt;&gt; <FONT color=#0000ff>4</FONT>;
    crc ^= (crc &lt;&lt; <FONT color=#0000ff>8</FONT>) &lt;&lt; <FONT color=#0000ff>4</FONT>;
    crc ^= ((crc &amp; <FONT color=#0000ff>0xff</FONT>) &lt;&lt; <FONT color=#0000ff>4</FONT>) &lt;&lt; <FONT color=#0000ff>1</FONT>;
</PRE>
<HR align=center>

<P><I><FONT size=2><FONT color=#800080><B>Note:</B> It is best not to alter this 
code. For example, </FONT><FONT 
color=#008000>(crc&lt;&lt;8)&lt;&lt;4</FONT><FONT color=#800080> does not 
generate the same code as </FONT><FONT color=#008000 
size=2>crc&lt;&lt;12</FONT><FONT color=#800000 size=2>. </FONT><FONT 
color=#800080 size=2>Although the result of the computation is the same, the 
latter generates much more code and executes slower.</FONT></FONT></I> 
<P>
<HR align=center>

<P align=center><FONT color=#800000 size=2>Copyright&nbsp;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -