开发者

conversion - ASCII hex to float in c++

开发者 https://www.devze.com 2023-02-10 22:16 出处:网络
I have a string containing, for example \"3F800000\". This is a hexadeci开发者_运维百科mal representation of the float 1.0Only I can\'t seem to find any convenient way of making this conversion in C+

I have a string containing, for example "3F800000".

This is a hexadeci开发者_运维百科mal representation of the float 1.0 Only I can't seem to find any convenient way of making this conversion in C++. Suggestions?


Assuming 32-bit int and float,

unsigned int x;
std::stringstream ss;
ss << std::hex << "3F800000";
ss >> x;
return reinterpret_cast<float&>(x);
0

精彩评论

暂无评论...
验证码 换一张
取 消