There is an int variable, say 0xFF00FF00. You need to get a byte array consisting of {FF, 00, FF, 00} elements.
Question. Are there any built-in mechanisms in .NET for this task, if there are any?
Use BitConverter: BitConverter.GetBytes(Int32)
https://msdn.microsoft.com/ru-ru/library/de8fssa4(v=vs.110).aspx
You can do it with your hands:
int myInt = 12345; byte[] myByte = { (byte)myInt, (byte)(myInt >> 8), (byte)(myInt >> 16), (byte)(myInt >> 24) }; Source: https://ru.stackoverflow.com/questions/678021/
All Articles