The BitConverter.ToString gives a hexadecimal in the format 'XX-XX-XX-XX'
Is there an opposite method to this so that I can obtain the original byte array from a string as given in this format?
The BitConverter.ToString gives a hexadecimal in the format 'XX-XX-XX-XX'
Is there an opposite method to this so that I can obtain the original byte array from a string as given in this format?
Use of string.Split, then byte.Parse in a loop is the simplest way. You can squeeze out a little more performance if you know that every byte is padded to two hex digits, there's always exactly one dash in between, by skipping the string.Split and just striding through three characters at a time.
No, but its easy to implement:
string s = "66-6F-6F-62-61-72";
byte[] bytes = s.Split('-')
.Select(x => byte.Parse(x, NumberStyles.HexNumber))
.ToArray();