You are here:

C++/converting byte sequence to float


Hi all,
I have a sequence of bytes of video frames. i will read the sequence of bytes to a buffer, and convert the sequence of bytes to float to use the value (for some thresholding for example}. how can i convert the sequence of bytes to float (one byte has to be converted to float)?

To be able to answer your question I need to understand what are the contents of one byte of the sequence. For example, if it contains integer, you could cast (reinterpret_cast) the byte to an integer, and then cast (static_cast) it into float.  

float convert_frame_byte_to_float(char c) {
  int i = reinterpret_cast<int>(c);
  return static_cast<float>(i);

To be sure, I need to know the meaning of a byte in the sequence.  


All Answers

Answers by Expert:

Ask Experts


Amit Kumar


I can answer Cplusplus language and library questions, including STL, ACE, Boost. I have a good background in Mathematics.


Programming in CPP for about 8 years. Industry experience of 4 years.

Bachelors and Masters in Computer Science from Indian Institute of Technology Delhi.

©2017 All rights reserved.

[an error occurred while processing this directive]