Skip to content

Instantly share code, notes, and snippets.

@jmcd
Created September 12, 2017 13:19
Show Gist options
  • Save jmcd/1e1011f27a438f22804762069a92d822 to your computer and use it in GitHub Desktop.
Save jmcd/1e1011f27a438f22804762069a92d822 to your computer and use it in GitHub Desktop.
Byte array to ints
public static class Bits
{
public static int[] ToInt32s(byte[] bytes)
{
var paddedBytes = new byte[bytes.Length + 3];
Array.Copy(bytes, paddedBytes, bytes.Length);
var numberOfInts = (bytes.Length + 3) / 4;
var ints = new int[numberOfInts];
for (var i = 0; i < numberOfInts; i++)
{
ints[i] = BitConverter.ToInt32(paddedBytes, i * 4);
}
return ints;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment