endian="big" , not "high" :
> to.read = file("~/Downloads/t10k-images-idx3-ubyte", "rb")
magic number:
> readBin(to.read, integer(), n=1, endian="big") [1] 2051
number of images:
> readBin(to.read, integer(), n=1, endian="big") [1] 10000
number of rows:
> readBin(to.read, integer(), n=1, endian="big") [1] 28
Number of columns:
> readBin(to.read, integer(), n=1, endian="big") [1] 28
here are the data:
> readBin(to.read, integer(), n=1, endian="big") [1] 0 > readBin(to.read, integer(), n=1, endian="big") [1] 0
as described in the training kit data on the website.
Now you just need to loop and read the 28 * 28-byte pieces into the matrices.
Start again:
> to.read = file("~/Downloads/t10k-images-idx3-ubyte", "rb")
skip header:
> readBin(to.read, integer(), n=4, endian="big") [1] 2051 10000 28 28
should really get 28.28 from the header read, but hard-coded here:
> m = matrix(readBin(to.read,integer(), size=1, n=28*28, endian="big"),28,28) > image(m)
Perhaps you need to rearrange or flip the matrix, I think this is an inverted "7".
par(mfrow=c(5,5)) par(mar=c(0,0,0,0)) for(i in 1:25){m = matrix(readBin(to.read,integer(), size=1, n=28*28, endian="big"),28,28);image(m[,28:1])}
gets you:

Oh, and Google leads me to: http://www.inside-r.org/packages/cran/darch/docs/readMNIST, which may be useful.