Why Isn't My Floating Point Values Printing Properly?

前端 未结 4 2049
-上瘾入骨i
-上瘾入骨i 2021-01-24 07:50

I am trying to print out the floating point values 0x40a00000 and 0xc0200000. But the values that I print out and the correct values according to the IEEE-754 Floating Point Con

4条回答
  •  北荒
    北荒 (楼主)
    2021-01-24 08:30

    These aren't doing what you think they do:

    float tmp1 = 0x40a00000;
    float tmp2 = 0xc0200000;
    

    You are simply using the hexadecimal representation of the decimal integers that are getting printed; they do not shove these bytes in so they can be interpreted as floats.

    It sounds like what you want to do is (somehow) get the bytes you want somewhere, get the address of that, and cast it to be a pointer to a float, which when dereferenced will be interpreted as a float.

提交回复
热议问题