CRC-16演算法實現)

來源:互聯網
上載者:User

http://www.smgblog.cn/article/mywork/74.htm

為了保證資料轉送的可靠性,在電腦網路傳輸資料時,必須採用各種差錯檢測措施。目前在資料連結層廣泛使用了循環冗餘檢查CRC(Cylic Redundancy Check)的檢錯技術。

CRC運算的文字描述這裡不再介紹。

用C#語言編寫的CRC-16編碼程式如下:

程式介面:

程式碼(演算法部分):
        //C#代碼,genPoly為產生多項式(16進位)
        private int genPoly = 0x18005;
        private void byteFCS(ref int FCS, char ch)
        {
            FCS ^= (ch<<8);
            for (int i = 0; i < 8; i++)
                if ((FCS & 0x8000) >= 0x8000)
                    FCS = (FCS << 1) ^ genPoly;
                else
                    FCS <<= 1;
            FCS &= 0xffff;
        }

        private int blockFCS(string block)
        {
            int FCS = 0;
            for (int i = 0; i < block.Length; i++)
            {
                char temp = block[i];
                byteFCS(ref FCS, temp);
            }
            return FCS;
        }

程式為:點擊下載(6.6 KB)
[2010-03-21 04:28 PM; 下載次數:135]

程式源碼為:點擊下載(39.31 KB)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.