public void ToInt32_ForPositiveNumber_ReturnsExpectedValue() { var input = GetBytes(0x11, 0x22, 0x33, 0x44); const int expected = 0x11223344; var actual = NumericConverter.ToInt32(input); Assert.That(actual, Is.EqualTo(expected), actual.ToString("x")); }
public void ToInt32_FoNegativeNumber_ReturnsExpectedValue() { var input = GetBytes(0x88, 0x99, 0xaa, 0xbb); const int expected = -0x77665545; var actual = NumericConverter.ToInt32(input); Assert.That(actual, Is.EqualTo(expected), actual.ToString("x")); }
public static int ReadInt32(Stream stream, int count) { var offset = 4 - count; var buffer = new byte[4]; var bytesRead = stream.Read(buffer, offset, count); if (bytesRead < count) { throw Exceptions.UnexpectedEnd(); } return(NumericConverter.ToInt32(buffer)); }