Helper.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace ActuBoardAPI
  6. {
  7. class Helper
  8. {
  9. public static byte[] IntToHexByte(int i)
  10. {
  11. byte[] intBytes = BitConverter.GetBytes(i);
  12. if (BitConverter.IsLittleEndian)
  13. Array.Reverse(intBytes);
  14. return intBytes;
  15. }
  16. public static String IntToHex(int i)
  17. {
  18. return i.ToString("X2");
  19. }
  20. public static String IntArrayToNumHexString(int[] cids, bool leadingCnt)
  21. {
  22. String channels = "";
  23. if (cids.Length > 0)
  24. {
  25. if(leadingCnt)
  26. channels += Helper.IntToHex(cids.Length);
  27. foreach (int c in cids)
  28. channels += Helper.IntToHex(c);
  29. }
  30. return channels;
  31. }
  32. public static String IntArrayToNumHexString(int[] cids)
  33. {
  34. return IntArrayToNumHexString(cids, true);
  35. }
  36. }
  37. }