📄 ccitt crc16 code.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 >> <FONT color=#0000ff>8</FONT>) | (crc << <FONT color=#0000ff>8</FONT>);
crc ^= ser_data;
crc ^= (<B>unsigned char</B>)(crc & <FONT color=#0000ff>0xff</FONT>) >> <FONT color=#0000ff>4</FONT>;
crc ^= (crc << <FONT color=#0000ff>8</FONT>) << <FONT color=#0000ff>4</FONT>;
crc ^= ((crc & <FONT color=#0000ff>0xff</FONT>) << <FONT color=#0000ff>4</FONT>) << <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<<8)<<4</FONT><FONT color=#800080> does not
generate the same code as </FONT><FONT color=#008000
size=2>crc<<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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -