白衣染霜花
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{ class Program { //ModBus C# CRC16校验算法 public static int[] crc16(int[] data) { int[] temdata = new int[data.Length + 2]; int xda, xdapoly; int i, j, xdabit; xda = 0xFFFF; xdapoly = 0xA001; for (i = 0; i >= 1; if (xdabit == 1) xda ^= xdapoly; } } Array.Copy(data, 0, temdata, 0, data.Length); temdata[temdata.Length - 2] = (int)(xda & 0xFF); temdata[temdata.Length - 1] = (int)(xda >> 8); return temdata; } static void Main(string[] args) { int[] data = { 01, 03, 11, 184, 00, 13 }; int[] d1 = crc16(data); Console.WriteLine(""); for (int i = 0; i
0
0