Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. /// <summary>
  2. /// Получение байт из HEX
  3. /// </summary>
  4. /// <param name="hex"></param>
  5. /// <returns></returns>
  6. public static byte[] Unpack(string hex)
  7. {
  8.     return Enumerable.Range(0, hex.Length)
  9.                         .Where(x => x % 2 == 0)
  10.                         .Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
  11.                         .ToArray();
  12. }
  13.  
  14. /// <summary>
  15. /// Получение HEX из байт
  16. /// </summary>
  17. /// <param name="array"></param>
  18. /// <returns></returns>
  19. public static string Pack(byte[] array)
  20. {
  21.     string result = "";
  22.     foreach (var item in array)
  23.         result += String.Format("{0,2}", Convert.ToString(item, 16)).Replace(' ', '0');
  24.     return result.ToUpper();
  25. }
  26.  
  27.  
  28.  
  29. //Пример
  30.  
  31. Unpack("0899aabbccddeeff0011223344556677fedcba98765432100123456789abcdef");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement