-
Hi everyone, In the Zephyr RTOS environment, I'm looking for a clean way to convert a float to a uint32_t (bitwise, preserving the IEEE 754 representation) and back again. I'm aware of the sys_put_be32, sys_get_le16, etc., functions for byte order handling, but I haven't found anything like a sys_float_to_u32() or similar. Right now, I'm using the following approach: `#include <stdint.h> union FloatUInt32 { // Convert float to uint32_t (bitwise) // Convert uint32_t to float (bitwise) This works fine, but I’m wondering: Is there a built-in or recommended way to do this in Zephyr? Is there any concern with strict aliasing or portability using the union approach? Would it be better to use memcpy() in this context? Appreciate any advice or pointers. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
memcpy() is better portability-wise |
Beta Was this translation helpful? Give feedback.
-
sys_put_be and sys_put_le does the job. |
Beta Was this translation helpful? Give feedback.
sys_put_be and sys_put_le does the job.