Convert Decimal to Char Array in Arduino

Posted on

In this article, I wrote to you an example of how to easily convert a decimal into a char array on Arduino. To convert a decimal number to a char array in Arduino, you can use the itoa() function. Here’s an example:

int num = 123;
char charArray[4];

itoa(num, charArray, 10); // 10 is the base

Serial.println(charArray); // prints "123"

In this example, itoa() the function takes three arguments: the decimal number you want to convert (num), the char array where you want to store the result (charArray), and the base you want to use for the conversion (in this case, 10 for decimal).

After calling itoa(), the charArray will contain the converted number as a sequence of characters. Note that the charArray must have enough space to store the converted number plus a null terminator character ('\0').

You can then print the charArray using Serial.println() or use it in other ways as needed.

Read more:

Leave a Reply