I have a method which gets a string of consecutive bytes and i need an array of bytes out of it:
void GetByteArray(string paddedResistance)
{
unsigned char cmd[4]={0x00,0x00,0x00,0x00};
list<string> resistanceBytesAsString;
for (int i = 0; i < paddedResistance.size(); i+=2)
{
resistanceBytesAsString.push_back(paddedResistance.substr(i, 2));
}
}
This is the input value : "00000100"
and i will split it and add it to the list as four separate strings:
00 00 01 00
I need to convert each of them in order to be able to populate the cmd unsigned char array but i can't figure out how to do it.
In C# i would use
Convert.ToByte(myString, 16);
to populate a byte array.