You are here:

C++/converting byte sequence to float

Advertisement


Question
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)?
thx,

Answer
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.  

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Amit Kumar

Expertise

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

Experience

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

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

©2016 About.com. All rights reserved.