Hello,
My apologies if this is a naive question. How do I convert a String which has hex values to a byte array that has those hex values?
This:
Stirng s = "0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff";
Needs to be converted to this:
char test[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
I used the following procedure. It does convert it, however, each character is saved as a character as opposed to hex value:
unsigned int str_len = s.length()+1;
char charArray[str_len];
s.toCharArray(charArray, str_len);
Any help will be appreciated. Thank you!
1. You have:
Stirng s = "0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff"; //here, there is a difference between f and F
==> Stirng s = {0x30, 0x78, 0x66, 0x66, 0x2C, ..., 0x20, 0x30, 0x78, 0x66, 0x66, 0x00};
2. You want:
byte test[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};//here, no difference between f and F
In what practical system/processing, you need this kind of transformation?
GolamMostafa:
In what practical system/processing, you need this kind of transformation?
I have an E-ink display that I am trying to update by making HTTP calls from my Arduino nano IoT. This is the value of an image converted to 1 bitmap and then into a byte array and sent over HTTP to my Arduino.