Getting the IEEE Single-precision bits for a float

后端 未结 4 1756
长情又很酷
长情又很酷 2021-01-07 03:54

I need to write an IEEE single-precision floating point number to a 32-bit hardware register at a particular address. To do that, I need to convert a variable of type float

4条回答
  •  自闭症患者
    2021-01-07 04:10

    You could creat a union type that contains a float and an unsigned int, store a value into the float member, then read it out of the int, like so:

    union reg_val
    {
      float f_val;
      unsigned int i_val;
    } myRegister;
    myRegister.f_val = 2.39;
    printf("target = %08X", myRegister.i_val);
    

提交回复
热议问题