Okay, I have a API call that is sending the Arduino a 4 digit number as a string (from the sending side) as part of a randomizing action. I need to convert this to a byte though for the program to work.
Input: String 4231
Output: byte {4, 2, 3, 1}
EDIT - fix hex values
Do you want the bytes to be the binary versions of the string characters or to just separate the characters in the string. For example do you want the first byte to be hex 04 or hex 34?
or, do you want the string 4231 to become a single number, 4231, as in four thousand, two hundred and thirty one? That is another possible interpretation of your question. afterall, you said
Well I figured it out. In my case, since I could already send it as a String, I used substring to get the individual digits with .toInt() to convert from String to int. Then manually saved the array calling each slot in the array and saving each location to that position
substring is relatively "heavy". It has to allocate memory for a whole new String. Use [] element access to get each character and then convert it to a byte value:
void apiGameOrder(const String& receivedOrder) {
for (int i = 0; i < 4; ++i) {
order[i] = receivedOrder[i] - '0';
}
}