I have an incoming string 68016101061B4A60193390662046804020422044204000420040402060226024676DB16 and I want to convert into 0x68 0x01 0x61 0x01 0x06 0x1B 0x4
68016101061B4A60193390662046804020422044204000420040402060226024676DB16
0x68 0x01 0x61 0x01 0x06 0x1B 0x4
If you want to use pure LINQ, you can do something along the lines of
data .Select((x,i) => (Index: i, Value: x)) .GroupBy(tuple => tuple.Index / 2, tuple => tuple.Value, (_,values) => "0x" + string.Join("",values)) .Select(x => Convert.ToByte(x, 16)) .ToArray();
if you want a ridiculous one-liner.