I have tried to convert the number that a reading returns to me to hexadecimal. I have not found any reference.
This is the code:
byte dummy = 0x00;
byte readCard[4];
String datoWifi = "";
for (int i = 0; i < 4; i++) { //
readCard[i] = mfrc522.uid.uidByte[i];
//dummy = (readCard[i], HEX); //esto no funciona
datoWifi += (String) mfrc522.uid.uidByte[i];
Serial.print(readCard[i], HEX);//de esta manera se imprime correctamente
}
Using Serial.print(readCard[i], HEX);
the hexadecimal value is printed perfectly, however what I need is to be able to construct datoWifi
that it is a type variable String
not with the returned numbers, but with the conversion already done.
I hope that there is some function already created for it and that the solution is not to create the function from scratch because that is what I want to avoid.
What you need is to use the proper constructor :
String
For this type of conversions you have the library
iomanip
(IO MANIPulation). What happens is that this library only works with streams . So the solution is to usestringstream
and then dump the result to your variablestring
:If you need the
0x
typical numbers in hexadecimal, you will have to add it manually: