Skip to content

Instantly share code, notes, and snippets.

@hmemcpy
Created August 23, 2012 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hmemcpy/3434473 to your computer and use it in GitHub Desktop.
Save hmemcpy/3434473 to your computer and use it in GitHub Desktop.
Better way to indian?
// converts 0x00010203 to a byte array, containing: 0x03, 0x02, 0x01, 0x00
public static byte[] ToBigEndian(int data)
{
var result = new byte[4];
result[0] = (byte)data;
result[1] = (byte)(((uint)data >> 8) & 0xFF);
result[2] = (byte)(((uint)data >> 16) & 0xFF);
result[3] = (byte)(((uint)data >> 24) & 0xFF);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment