Casting an array of unsigned chars to an array of floats
问题 What is the best way of converting a unsigned char array to a float array in c++? I presently have a for loop as follows for (i=0 ;i< len; i++) float_buff[i]= (float) char_buff[i]; I also need to reverse the procedure, i.e convert from unsigned char to float (float to 8bit conversion) for (i=0 ;i< len; i++) char_buff[i]= (unsigned char) float_buff[i]; Any advice would be appreciated Thanks 回答1: I think the best way is to use a function object: template <typename T> // T models Any struct