C # implement CRC32 function __ function

Source: Internet
Author: User
Tags crc32 crc32 checksum

The Crc32 invocation method for PHP is as follows

<?php
Echo crc32 ("ABCD");
3675725989
?>

C # 's CRC32 function is implemented as follows

Using System;
Using System.IO;
Using System.Collections;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;

Using System.Security.Cryptography;
        Namespace ConsoleApplication1 {class Crc32cls {static protected ulong[] crc32table;
            Generate CRC32 Code table 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 = (Cr
                    C >> 1) ^ 0xedb88320;
                else CRC >>= 1;
            } Crc32table[i] = CRC; }//Gets the CRC32 checksum of the string static public ulong Getcrc32str (string sinputstring) {//
            Generate Code table 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; } class Program {static void Main (string[] args) {Console.WriteLine (CRC32CLS.G
            Etcrc32str ("ABCD")); Print 3675725989}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.