This example show how to convert int to String in various number base, BIN, HEX, DEC.
void setup() {
}
void loop() {
int i = 1023;
Serial.println("http://arduino-er.blogspot.com/");
Serial.println("Test String: convert int to String");
Serial.println();
Serial.println("String(i) = " + String(i));
Serial.println();
Serial.println("String(i, BIN) = "
+ String(i, BIN));
Serial.println("String(i, HEX) = "
+ String(i, HEX));
Serial.println("String(i, DEC) = "
+ String(i, DEC));
Serial.println();
Serial.println("String(i+i, BIN) = "
+ String(i+i, BIN));
Serial.println("String(i+i, HEX) = "
+ String(i+i, HEX));
Serial.println("String(i+i, DEC) = "
+ String(i+i, DEC));
Serial.println();
Serial.println("String(i, BIN)+String(i, BIN) = "
+ String(i, BIN)+String(i, BIN));
Serial.println("String(i, HEX)+String(i, HEX) = "
+ String(i, HEX)+String(i, HEX));
Serial.println("String(i, DEC)+String(i, DEC) = "
+ String(i, DEC)+String(i, DEC));
Serial.println();
delay(1000);
}
|
Convert int to String |
Nice concise code. Do you have similar for the reverse, String to int?
ReplyDeletePresumably you would use isDigit() and toInt().