我不知道Xmodem CRC的初始化 [英] I don't know the initialisation for a Xmodem CRC

查看:68
本文介绍了我不知道Xmodem CRC的初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

	class Program
	{
		public static int calcrc(byte[] ptr)
		{
			int crc = 0;
		    
unchecked{
		    for (int j = 0; j < ptr.Length; j++)
		    {
		    	crc = crc ^ (short)(ptr[j] << 8);
		        for (int i = 0; i < 8; i++)
		        {
		        	if ((crc & 0x8000) != 0)
		            crc = (short)((crc << 1) ^ 0x1021);
		            else
		            crc = (short)(crc << 1);
		        }
		    }
		  }
		    return (crc & 0xFFFF);   
		}
		
		
			
		public static void Main(string[] args)
		{
			string a = "123456789";
			
			byte [] number = new byte[128];

			for (int i=0; i<a.Length; i++)
			{
				number[i]=(byte)a[i];
			}
			
			Console.Write("\n CRC number: " + calcrc(number));
						
			Console.Write("Press any key to continue . . . ");
			Console.ReadKey(true);
		}
	}
}

推荐答案

参见 XMODEM [ ^ <维基百科中的/ a>]。



根据参考链接4,您将转到
http://techheap.packetizer.com/communication/modems/xmodem-ymodem_reference.html [ ^ ](参见7.1 CRC计算一节)。



另请参阅外部链接 http://wiki.synchro.net / ref:xmodem [ ^ ](CRC部分计算规则)。



[更新:固定维基百科链接]
See XMODEM[^] in the Wikipedia.

Following the reference link 4 brings you to http://techheap.packetizer.com/communication/modems/xmodem-ymodem_reference.html[^] (see section "7.1 CRC Calculation").

See also the external link http://wiki.synchro.net/ref:xmodem[^] (section "CRC Calculation Rules").

[UPDATE: Fixed Wikipedia link]


这篇关于我不知道Xmodem CRC的初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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