Can someone please explain how float to uint32_t casting works? Is it a valid conversion?
The output of the first line in the below code make sense to me, but the rest are I can't figure out myself.
cout<<uint8_t(256+33)<<'\n';
cout<<uint8_t(float(256+33))<<'\n';
cout<<int(uint8_t(float(256+33)))<<'\n';
cout<<int(uint8_t(float(256+3)))<<'\n';
cout<<int(uint8_t(float(256+20)))<<'\n';
output
!
�
255
255
255
uint8_t(256+33) is int to unsigned char, and it gives !, which is what I expect. However, float to uint8_t does not work at all. And when I try to cast the output to int, it gives me constant number 255.
I've a vector<float> and want to convert it into vector<uint8_t>, which will to passed into a function. What it a valid way to convert float to uint8_t? Will static_cast<uint8_t> will work? Should I first convert float to int and then int to uint8_t?