Float to binary in C++

后端 未结 7 1414
孤独总比滥情好
孤独总比滥情好 2020-12-09 07:29

I\'m wondering if there is a way to represent a float using a char in C++?

For example:

int main()  
{  
    float test = 4.7567;  
    char result =         


        
7条回答
  •  我在风中等你
    2020-12-09 08:05

    You can create, for that number, a fixed point value using 2 bits for the whole number and 5 bits for the fractional portion (or 6 if you want it to be unsigned). That would be able to store roughly 4.76 in terms of accuracy. You don't quite have enough size to represent that number much more accurately - unless you used a ROM lookup table of 256 entries where you are storing your info outside the number itself and in the translator.

提交回复
热议问题