AryUtil.cs 758B

12345678910111213141516171819202122232425262728
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace GWSocketClient.util
  7. {
  8. public class AryUtil
  9. {
  10. public static string Bytes2Hex(byte[] bs)
  11. {
  12. return BitConverter.ToString(bs, 0, bs.Length).Replace("-", "").ToUpper();
  13. }
  14. public static byte[] Hex2Bytes(string hex)
  15. {
  16. hex = hex.Replace(" ", "");
  17. if (hex.Length % 2 != 0)
  18. hex += " ";
  19. byte[] returnBytes = new byte[hex.Length / 2];
  20. for (int i = 0; i < returnBytes.Length; i++)
  21. returnBytes[i] = Convert.ToByte(hex.Substring(i * 2, 2).Trim(), 16);
  22. return returnBytes;
  23. }
  24. }
  25. }