This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] TMS320F28.0025万C:将字节转换为浮点值

Guru**** 2455790 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1104087/tms320f280025c-convert-bytes-to-a-float-value

部件号:TMS320F28.0025万C

各位专家,您好!

我遇到了一个问题,我想将CAN数据接收转换为浮点值。 我想我不能正确理解C中的IEE754表示法。我很理解32位上浮点的分解,但我不知道如何从我的字节中获取浮点数字?  

可以帮我吗?

谢谢!

Damien

int32_t data;
void update_param_corrector(struct corrector_parameters * param)
{
    data = (int32_t)can_rx_buffer[4];
    data |= ((int32_t)can_rx_buffer[5] << 8);
    data |= ((int32_t)can_rx_buffer[6] << 16);
    data |= ((int32_t)can_rx_buffer[7] << 24);
    param->KP = (float32_t)data;
}

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好,
    这样的操作应该起作用:


    param->KP = *(float32_t*)&data;


    此致
    Andy

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    你好,Andy

    感谢您的回复,一切都好。

    Damien