Continuing the discussion from How best to convert `&[u8]` to `&[u16]`:
How to specify endian with this method?
Continuing the discussion from How best to convert `&[u8]` to `&[u16]`:
How to specify endian with this method?
You cannot, it will take the native endianess.
To be clear, you can't change the endianness if you want to re-use the memory as-is (i.e., borrow). That should be obvious. The data is laid out in memory as it is laid out however your system treats multi-byte types, i.e., native endianness.
If you want to convert between representations of different endianness, then you'll have to copy the values in order to rearrange bytes. Example.
Cool!
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.