Is .NET BinaryReader always little-endian, even on big-endian systems?

后端 未结 2 1636
清酒与你
清酒与你 2020-12-11 06:37

Microsoft documentation on BinaryReader for ReadUnt32 (for example) states: Reads a 4-byte unsigned integer from the current stream using little-endian encoding. However, is

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-11 07:36

    The documentation is certainly a hint that implementors on other platforms should use little-endian encoding, and Mono seems to respect this:

    public virtual uint ReadUInt32() {
    FillBuffer(4);
    
    return((uint) (m_buffer[0] |
               (m_buffer[1] << 8) |
               (m_buffer[2] << 16) |
               (m_buffer[3] << 24)));
    }
    

提交回复
热议问题