亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Is there CRC32 api in C#/.NET?

Is there CRC32 api in C#/.NET?

小怪獸愛吃肉 2018-09-07 12:13:34
Java version:public static long crc32(byte[] data) {     CRC32 crc32 = new CRC32();     crc32.update(data);         return crc32.getValue(); }How to implement it simplely in C#/.NET?
查看完整描述

2 回答

?
qq_笑_17

TA貢獻1818條經驗 獲得超7個贊

貌似沒有官方實現,百度兩個吧

查看完整回答
反對 回復 2018-09-23
?
Helenr

TA貢獻1780條經驗 獲得超4個贊

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;


namespace wcs_csharp_sdk.main.util

{

    public class CRC32

    {

        static protected ulong[] Crc32Table;

        //生成CRC32碼表

        static public void GetCRC32Table()

        {

            ulong Crc;

            Crc32Table = new ulong[256];

            int i, j;

            for (i = 0; i < 256; i++)

            {

                Crc = (ulong)i;

                for (j = 8; j > 0; j--)

                {

                    if ((Crc & 1) == 1)

                        Crc = (Crc >> 1) ^ 0xEDB88320;

                    else

                        Crc >>= 1;

                }

                Crc32Table[i] = Crc;

            }

        }

        //獲取byte[]的CRC32校驗值

        static public ulong GetCRC32(byte[] buffer)

        {

            //生成碼表

            GetCRC32Table();

            ulong value = 0xffffffff;

            int len = buffer.Length;

            for (int i = 0; i < len; i++)

            {

                value = (value >> 8) ^ Crc32Table[(value & 0xFF) ^ buffer[i]];

            }

            return value ^ 0xffffffff;

        }


        //獲取字符串的CRC32校驗值

        static public ulong GetCRC32(string sInputString)

        {

            //生成碼表

            GetCRC32Table();

            byte[] buffer = System.Text.ASCIIEncoding.ASCII.GetBytes(sInputString);

            ulong value = 0xffffffff;

            int len = buffer.Length;

            for (int i = 0; i < len; i++)

            {

                value = (value >> 8) ^ Crc32Table[(value & 0xFF) ^ buffer[i]];

            }

            return value ^ 0xffffffff;

        }

       

       

    }

}


查看完整回答
反對 回復 2018-09-23
  • 2 回答
  • 0 關注
  • 551 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號