convert uint8_t to string

Hi,

How can I convert uint8_t to String

namespace convert
{
      String ToString(uint8_t num)
      {
            String str="";
            char ascii[32];

            int temp1 = (num - (int)num) * 100;
            sprintf(ascii,"%0d.%d", (int)num, temp1);

            str+=ascii;

            return str;
      }
      String ToString(float num)
      {
            String str="";
            char ascii[32];

            int temp1 = (num - (int)num) * 100;
            sprintf(ascii,"%0d.%d", (int)num, temp1);

            str+=ascii;

            return str;
      }

Is this code working ?

Just use one little function called itoa, that will that one int/uint8_t and will spit out one string.

Under arduino env I can use itoa ?

Every standart function of C is implemented in the avr-gcc compiler wich is the one used by the arduino IDE. For the specific itoa just use google and search itoa avr: http://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html#ga4f6b3dd51c1f8519d5b8fce1dbf7a665

You better use itoa() if you want accurate results. Your code won't produce accurate results:

            int temp1 = (num - (int)num) * 100;

Casting num to an int doesn't change it's value, since it is being cast to a larger type. So, you have (num - num) * 100 being assigned to temp1. Even with my shoes on, I can tell you that temp1 will be 0, for any value of num.

A String created from an unsigned 8 bit int does not have a decimal point in it, either.