c++ - Casting an array of unsigned chars to an array of floats -


What is the best way to change an unsigned char array from float array in c ++?

I is currently following for loop:

 for  (i = 0; i  

I also have to reverse the process, that is to convert from unsigned char to float (float to 8 bit conversion)

  (i = 0; I & lt; Len; i ++) char_buff [i] = (unsigned char) float_buff [i];  

Any advice would be appreciated

thanks

I think the best way to use the function object is:

  template & lt; Typename T & gt; // T Model any structure static_cast_func {template & lt; Typename T1 & gt; // T1 model TT operator () (const T1 and x) const {return static_cast & lt; T & gt; Fixed variable types for (x); }};  

After that:

  std :: transform (char_buff, char_buff + len, float_buff, static_cast_func & lt; float & gt; ()); Std :: transform (float_buff, float_ff + lane, four-buff, static_cast_function & lt; unsigned char & gt; ()); This is most readable because it says what is being done in English: using a fixed wrist to change the sequence of a different type. And future can be done in a row. 


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -