How can I convert a git hash to a byte array with length 20 in C#? At the moment I represent the git hash as a string:
string gitHash = "0x29932f3915935d773dc8d52c292cadd81c81071d";
I have tried this:
byte[] gitHashBytes = System.Text.Encoding.ASCII.GetBytes(gitHash);
Array.Resize(ref gitHashBytes, 20);
But I actually want to convert the hex number to the byte array and not the string representation of it.
I need this to save the git hash in a smart contract where I am using bytes20 as data structure.
Why does the way I tried it above not work and just cut off the the hash after 20 digits? And what's the difference to the conversion in the proposed answer here: How can I convert a hex string to a byte array?