如何在VB.NET中计算CRC16校验和 [英] How do i calculate CRC16 Checksum in VB.NET

查看:399
本文介绍了如何在VB.NET中计算CRC16校验和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部,
任何人都可以在VB.NET中为计算String的CRC提出建议.
谢谢您.

Hai All,
Can Anybody give a sugession for calculating CRC for String in VB.NET.
Thank You

推荐答案

确定.这足够详细地描述了算法:
http://en.wikipedia.org/wiki/Crc16 [ http://en.wikipedia.org/wiki/Computation_of_CRC [
Sure. This describes the algorithm in sufficient detail:
http://en.wikipedia.org/wiki/Crc16[^],
http://en.wikipedia.org/wiki/Computation_of_CRC[^].

This is all you need to write this code.

The only problem is to represent the string as numeric data. The simplest way to do so is to serialize the string using one of the Unicode UTF encodings into the array of bytes and then apply the CRC algorithm to this array. The result will depend on encoding, but it does not matter as the information is equivalent; it''s only important that you use the same encoding consistently and don''t use non-Unicode encoding which means loss of information in the general-case Unicode input.

Here is how:
string input = //...
//...
byte[] data = System.Text.Encoding.UTF8.GetBytes(input);



请参阅:
http://msdn.microsoft.com/en-us/library/system.text. encoding.aspx [^ ].

请注意,.NET内部在内存中使用的编码为UTF-16LE.在这种意义上,所有UTF编码都是等效的,即使它们包含的字符编码点需要16个或更多(最多32个)位才能容纳,它们也可以对任何Unicode测试进行编码而不会造成任何损失.面向字节的UTF-8使用可变大小的字节序列表示一个字符,而UTF-16使用一个16位字或两个这样的字(称为代理对" )表示单个字符.这样,可以表示Unicode范围0到0x10FFFF的任何字符.

请参阅:
http://en.wikipedia.org/wiki/Unicode [ http://en.wikipedia.org/wiki/Code_point [ http://unicode.org/ [ ^ ],
http://unicode.org/faq/utf_bom.html [



Please see:
http://msdn.microsoft.com/en-us/library/system.text.encoding.aspx[^].

Note that the encoding used by .NET internally in memory is UTF-16LE. All UTF encodings are equivalent in that sense that they encode any Unicode test without any losses, even if the text contains characters with the code point requiring 16 or more (up to 32) bits to fit. Byte-oriented UTF-8 uses variable-size byte sequences to represent one character, and UTF-16 uses one 16-bit words or two such words (called surrogate pair) to represent a single character. In this way, any character in the Unicode range 0 to 0x10FFFF can be represented.

Please see:
http://en.wikipedia.org/wiki/Unicode[^],
http://en.wikipedia.org/wiki/Code_point[^],
http://unicode.org/[^],
http://unicode.org/faq/utf_bom.html[^].

—SA


这篇关于如何在VB.NET中计算CRC16校验和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆