using System;
using System.Text;
using System.Linq;
internal class Program
{
static void PrintByteArray(byte[] bytes) {
var sb = new StringBuilder("byte[] = ");
foreach (var b in bytes) {
sb.Append(b + ", ");
}
Console.WriteLine(sb.ToString());
}
public static byte[] HexStringToByteArray(string hex) {
hex = hex.Length % 2 == 1 ? "0" + hex : hex; // Pad with leading zero if necessary
return Enumerable.Range(0, hex.Length)
.Where(x => x % 2 == 0)
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
.ToArray();
}
public static void Main(string[] args)
{
byte[] barr = HexStringToByteArray("1B6E2AC");
PrintByteArray(barr);
}
}
/*
run:
byte[] = 1, 182, 226, 172,
*/