我正在解析 C# 中的 MNIST 数据集,来自:http: //yann.lecun.com/exdb/mnist/
我正在尝试Int32
从二进制文件中读取第一个:
FileStream fileS = new FileStream(fileName, FileMode.Open, FileAccess.Read);
BinaryReader reader = new BinaryReader(fileS);
int magicNumber = reader.ReadInt32();
但是,它给了我一个无意义的数字:50855936。
如果我使用File.ReadAllBytes()
buffer = File.ReadAllBytes(fileName);
然后查看字节,它工作正常(前四个字节现在代表 2049),我对 BinaryReader 做错了什么?
文件格式如下(我正在尝试读取第一个幻数):
All the integers in the files are stored in the MSB first (high endian) format used by most non-Intel processors. Users of Intel processors and other low-endian machines must flip the bytes of the header.
训练集标签文件(train-labels-idx1-ubyte):
[offset] [type] [value] [description]
0000 32 bit integer 0x00000801(2049) magic number (MSB first)
0004 32 bit integer 60000 number of items
0008 unsignebyte ?? label
0009 unsigned byte ?? label
........
xxxx unsigned byte ?? label
The labels values are 0 to 9.d