Created
September 12, 2017 13:19
-
-
Save jmcd/1e1011f27a438f22804762069a92d822 to your computer and use it in GitHub Desktop.
Byte array to ints
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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