How can I convert an array of bytes that I read from my serial into hex then store them into a string?
I want to find some hex values and I thought that storing them into a string then using the substring to find them will be the easiest way..
Ex:
Incoming array : D18A6851838004D18AF9
What i want to find : 68518380
I tried directly using:
[...]
String message = "";
while ( x<=length){
//other stuff;
message += (sEventBuffer[x],HEX);
x++;
[...]
Then I tried to convert the (sEventBuffer[x],HEX)
into a char and then store the char into the string. That didn't work either.
(And yes, I did tried tot compare each byte individually)
int by1 = 0;
int by2 = 0;
int by3 = 0;
int by4 = 0;
int by5 = 0;
if (sEventBuffer[x] == byte(68)){
by1 = 1;
}
if ( (by1 == 1) & (sEventBuffer[x] == byte(5)) ){
by2 = 1;
}
if ((by1 == 1) & (by2 == 1) & (sEventBuffer[x] == byte(18))){
by3 = 1;
}
if ((by1 == 1) & (by2 == 1) & (by3 == 1) & (sEventBuffer[x] == byte(38))){
by4 = 1;
}
if ((by1 == 1) & (by2 == 1) & (by3 == 1) & (by4 == 1) & (sEventBuffer[x] == byte(0))){
by5 = 1;
}
//if all by from 1 to 5 are 1 then do something