fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Test
  5. {
  6. //
  7.  
  8. public static ushort CalculateCRC(List<byte> byteList)
  9. {
  10.  
  11. ushort crc = 0x0;
  12. for (int j = 0; j < byteList.Count; j++)
  13. {
  14. int c = byteList[j];
  15.  
  16. for (int i = 0; i < 8; i++)
  17. {
  18. bool c15 = ((crc >> 15 & 1) == 1);
  19. bool bit = ((c >> (7 - i) & 1) == 1);
  20.  
  21. crc <<= 1;
  22.  
  23. if (c15 ^ bit)
  24. {
  25. crc ^= 0x1021; // 0001 0000 0010 0001 (0, 5, 12)
  26. }
  27. }
  28. }
  29.  
  30. crc &= (ushort)0xFFFF;
  31.  
  32. return crc;
  33. }
  34.  
  35. public static void Main()
  36. {
  37. // 00 00 00 00 00 00 00 00 00 8F 02 F1 01 F3 01 00 00
  38. //byte[] byteList = ;
  39. List<byte> lst = new List<byte>(new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8F, 0x02, 0xF1, 0x01, 0xF3, 0x01, 0x00, 0x00});
  40.  
  41. Console.WriteLine(CalculateCRC(lst));
  42. }
  43.  
  44.  
  45.  
  46. }
Success #stdin #stdout 0s 131520KB
stdin
Standard input is empty
stdout
2380