Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Convert SQL Server Management Studio SSMS Varbinary Column Output to Byte Array C#
static void Main(string[] args)
// read input from local file (could also pass in via args)
var hexInput = File.ReadAllText("hexInput.txt");
// convert to binary, strip off first two chars 'Ox'
var byteArray = StringToByteArray(hexInput.Substring(2));
// write bytes to file
File.WriteAllBytes("output.file", byteArray);
public static byte[] StringToByteArray(string hex)
int cnt = hex.Length;
byte[] bytes = new byte[cnt / 2];
for (int i = 0; i < cnt; i += 2)
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
return bytes;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.