Is there a better way to write this than using BitConverter
?
public static class ByteArrayExtensions
{
public static int IntFromUInt24(this byte[] bytes)
{
if (bytes == null)
{
throw new ArgumentNullException();
}
if (bytes.Length != 3)
{
throw new ArgumentOutOfRangeException
("bytes", "Must have length of three.");
}
return BitConverter.ToInt32
(new byte[] { bytes[0], bytes[1], bytes[2], 0 }, 0);
}
}