Convert int[] to byte[]?
Could anyone help me convert an array of integers to an array of bytes?
12 Replies
BinaryPrimitives Class (System.Buffers.Binary)
Reads bytes as primitives with specific endianness.
Would this be a good idea?
that doesnt make sense, since byte's maximum value is 255
what if an integer is 512 ?
you probably want a 2d array
i assume they want to convert each int to an array of bytes
what they had originally makes perfect sense and works fine
absolutely no reason to correct that
unless they want a faster version
id allocate once and for it
more efficient than linq
Ero#1111
REPL Result: Success
Result: byte[]
Compile: 565.667ms | Execution: 44.727ms | React with ❌ to remove this embed.
ah, right
modix turns bytes into chars
Cyberrex#8052
REPL Result: Success
Result: string
Compile: 621.330ms | Execution: 50.969ms | React with ❌ to remove this embed.
I think I would use MemoryMarshal.Cast for this.
ah that slipped my mind, did not think thats what they meant
even tho i used those kinds of things in a project im working on