I have a problem when converting a char to hex value the code below works correctly when the char is a number but it's throw exception when the char is a latter
System.FormatException: 'Input string was not in a correct format
Code:
public byte[,] get_state(string plainText)
{
char[] cplainText = plainText.ToCharArray();
byte[,] state = new byte[4, 4];
plainText = plainText.Remove(0, 2);
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j+=2)
{
string sub = plainText.Substring((i * 4 + j), 2);
state[i, j] = Convert.ToByte(sub);
}
}
return state;
}
The input string was "0x3243F6A8885A308D313198A2e0370734" and the exception across when the iteration of "F6"