Convert int to byte array. C#

Question:

There is an int variable, let's say 0xFF00FF00. You need to get a byte array consisting of elements {FF, 00, FF, 00}.


Question. Does .NET have built-in mechanisms for this task, if so, which ones?

Answer:

Use BitConverter: BitConverter.GetBytes(Int32)

https://msdn.microsoft.com/en-us/library/de8fssa4(v=vs.110).aspx

Scroll to Top