Convert int[] to byte[]?
Could anyone help me convert an array of integers to an array of bytes?
Compile: 621.330ms | Execution: 50.969ms | React with ❌ to remove this embed.
even tho i used those kinds of things in a project im working oneven tho i used those kinds of things in a project im working onbyte[] bytes = intArray.SelectMany(BitConverter.GetBytes).ToArray()byte[][] bytes = intArray.Select(x => BitConverter.GetBytes(x)).ToArray();using System.Runtime.InteropServices;
int[] foo = { 1, 2, 3, 4, 5 };
byte[] bar = MemoryMarshal.AsBytes<int>(foo).ToArray();
barAQAAAAIAAAADAAAABAAAAAUAAAA=using System.Runtime.InteropServices;
int[] foo = { 1, 2, 3, 4, 5 };
byte[] bar = MemoryMarshal.AsBytes<int>(foo).ToArray();
string.Join("", bar)10002000300040005000Span<byte> bytes = MemoryMarshal.Cast<int, byte>(foo);