Reading MNIST by byte with python
<p>I am playing around with the MNIST dataset and I have encountered the following, which I don't quite understand. According to the 
<a href="http://yann.lecun.com/exdb/mnist/" rel="nofollow noreferrer">documentation</a> the data is formatted as follows:</p>

<pre><code>[offset] [type]          [value]          [description] 
0000     32 bit integer  0x00000801(2049) magic number (MSB first) 
0004     32 bit integer  60000            number of items 
0008     unsigned byte   ??               label 
0009     unsigned byte   ??               label 
........ 
xxxx     unsigned byte   ??               label
The labels values are 0 to 9.
</code></pre>

<p>Thus, I would expect bytes 4-8, corresponding to the number of items (60,000) to be:</p>

<pre><code>struct.pack('i', 60000)
&gt;&gt; '`\xea\x00\x00'
</code></pre>

<p>However, when I read the file byte-by-byte, it looks like they are in reverse order:</p>

<pre><code>with gzip.open(path_to_file, 'rb') as f:
    print struct.unpack('cccc', f.read(4))
    for i in range(4):
        print struct.unpack('c', f.read(1))
&gt;&gt; ('\x00', '\x00', '\x08', '\x01')
&gt;&gt; ('\x00', '\x00', '\xea', '`')
</code></pre>

<p>Clearly, I can reverse them to get the expected order, but I am confused as to why the bytes seem to reversed. </p>