float转uint8
时间: 2023-12-01 21:34:57 浏览: 111
c++ float转int
5星 · 资源好评率100%
将float转换为uint8数组的方法可以使用typecast函数。具体的代码如下所示:
float floatValue = 1.23;
uint8_t byteArray;
byteArray = (uint8_t)((*(uint32_t*)&floatValue) & 0xFF);
byteArray = (uint8_t)(((uint32_t*)&floatValue) >> 8 & 0xFF);
byteArray = (uint8_t)(((uint32_t*)&floatValue) >> 16 & 0xFF);
byteArray = (uint8_t)(((uint32_t*)&floatValue) >> 24 & 0xFF);
阅读全文