我对微软的BinaryReader有疑问。
来自https://referencesource.microsoft.com/#mscorlib/system/io/binaryreader.cs,
public virtual long ReadInt64() {
FillBuffer(8);
uint lo = (uint)(m_buffer[0] | m_buffer[1] << 8 |
m_buffer[2] << 16 | m_buffer[3] << 24);
uint hi = (uint)(m_buffer[4] | m_buffer[5] << 8 |
m_buffer[6] << 16 | m_buffer[7] << 24);
return (long) ((ulong)hi) << 32 | lo;
}
它将数据解析为Int64数据的两个部分(高32位,低32位)。但我认为这是多余的。所以下面的方法也应该有效。
public virtual long ReadInt64Other() {
FillBuffer(8);
return (long)m_buffer[0] |
(long)m_buffer[1] << 8 |
(long)m_buffer[2] << 16 |
(long)m_buffer[3] << 24 |
(long)m_buffer[4] << 32 |
(long)m_buffer[5] << 40 |
(long)m_buffer[6] << 48 |
(long)m_buffer[7] << 56;
}
Microsoft有没有理由使用上/下样式解析?