Copying a float into a uint8_t array efficiently

I am putting together a uint8_t array payload for my xbees and I am reading data from a sensor in a uint8_t array. This array is then copied into the payload with a for loop like this.

ds2438 hum1(&oneWire, TempSerial);                    //Call sensor
dtostrf(hum1.readHum(),5, 1, dtostrfbuffer);         //read humidity(float) into array buffer
humidity_string = dtostrfbuffer;                             // coppy into a string
for (  int j = 0; j < 6; j++) 
        payload[9+j] = humidity_string.charAt(j);

The location is always the same and the length of the data is always the same. Is there some way to avoid the for loop here or even the float the string conversion?

humidity_string = dtostrfbuffer;                             // coppy into a string

This does not copy to a string. It (wastefully) copies to a String. Big difference, and completely unnecessary.

What are you doing with the string representation of the humidity on the other end?

It might be better to send the humidity value in binary, and reconstruct the float on the other end.

I 100% agree, there is no reason to send it as a string. I would like to send it as binary which would make it much more compact. Could you recommend some code for assembling this? I could handle the receiving end after that.

For binary copying you could use memcpy ( Another idea for building your payload is a struct and union combination.