Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class Program
- {
- public static void Main()
- {
- Console.WriteLine("Hello World");
- byte[] arr = new byte[2];
- arr[0] = 0;
- arr[1] = 0xC4;
- Console.WriteLine("crc: "+Compute_CRC16_Simple(arr));
- }
- public static ushort Compute_CRC16_Simple(byte[] bytes)
- {
- const ushort generator = 0x8005; /* divisor is 16bit */
- ushort crc = 0; /* CRC value is 16bit */
- foreach (byte b in bytes)
- {
- crc ^= (ushort)(b << 8); /* move byte into MSB of 16bit CRC */
- for (int i = 0; i < 8; i++)
- {
- if ((crc & 0x8000) != 0) /* test for MSB = bit 15 */
- {
- crc = (ushort)((crc << 1) ^ generator);
- }
- else
- {
- crc <<= 1;
- }
- Convert.ToString(5, 2);
- Console.WriteLine("crc: "+Convert.ToString(crc, 2));
- }
- }
- return crc;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement