Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Получение байт из HEX
- /// </summary>
- /// <param name="hex"></param>
- /// <returns></returns>
- public static byte[] Unpack(string hex)
- {
- return Enumerable.Range(0, hex.Length)
- .Where(x => x % 2 == 0)
- .Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
- .ToArray();
- }
- /// <summary>
- /// Получение HEX из байт
- /// </summary>
- /// <param name="array"></param>
- /// <returns></returns>
- public static string Pack(byte[] array)
- {
- string result = "";
- foreach (var item in array)
- result += String.Format("{0,2}", Convert.ToString(item, 16)).Replace(' ', '0');
- return result.ToUpper();
- }
- //Пример
- Unpack("0899aabbccddeeff0011223344556677fedcba98765432100123456789abcdef");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement