Replies: 2 comments 3 replies
-
Fundamentally, you're just casting a You should basically only do this if you know with certainty the endianness of the system that produced the byte array. |
Beta Was this translation helpful? Give feedback.
-
Have a look at BinaryPrimitives. |
Beta Was this translation helpful? Give feedback.
-
If I use
MemoryMarshel.Cast
on different endian platform to cast sameSpan<byte>
, will I got the same result?For example:
here is a byte array of a date, it's got on little-endian platform:
{ 0xE5, 0x07, 0x03, 0x11 }
[0xE5, 0x07] => 2021
[0x03] => 3
[0x11] => 17
And I have a DateStruct:
Cast this byte array to struct:
So, If I run it on a big-endian platform, the value of date.year will be
2021
or58631
?I had read this: https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.memorymarshal.cast but still a bit confused.
Beta Was this translation helpful? Give feedback.
All reactions