I'm trying to read the ubyte format. I verified I'm on a little endian machine and have reversed the bits to little endian. The problem is however that the numbers I see in my file after conversion are way above 255.
Any ideas? I got the code from How to read MNIST data in C++? and made a few modifications to it but here is my code
if (fin.is_open())
{
    int magic_number=0;
    int number_of_images=0;
    int n_rows=0;
    int n_cols=0;
    fin.read((char*)&magic_number,sizeof(magic_number));
    magic_number= flipBytes(magic_number);
    fin.read((char*)&number_of_images,sizeof(number_of_images));
    number_of_images= flipBytes(number_of_images);
    fin.read((char*)&n_rows,sizeof(n_rows));
    n_rows= flipBytes(n_rows);
    fin.read((char*)&n_cols,sizeof(n_cols));
    n_cols= flipBytes(n_cols);
    if(fin2.is_open())
    {
        int magic_number_label = 0;
        int number_of_items = 0;
        fin2.read((char*)&magic_number_label, sizeof(magic_number_label));
        magic_number_label = flipBytes(magic_number_label);
        fin2.read((char*)&number_of_items, sizeof(number_of_items));
        number_of_items = flipBytes(number_of_items);
        log << "Magic Number: " << magic_number << "\n";
        log << "Number of Images: " << number_of_images << "\n";
        log << "Number of Rows: " << n_rows << "\n";
        log << "Number of Cols: " << n_cols << "\n";
        log << "------------------------------\n";
        log << "Magic Number Label: " << magic_number_label << "\n";
        log << "Number of Items: " << number_of_items << "\n";
        for(int i=0;i<number_of_images;++i)
        {
            for(int r=0;r<n_rows;++r)
            {
                for(int c=0;c<n_cols;++c)
                {
                    unsigned int temp=0;
                    fin.read((char*)&temp,sizeof(temp));
                    temp = flipBytes(temp);
                    fout << temp << ", ";
                }
            }
            //ATTACH ANSWER
            unsigned int temp;
            fin2.read((char*)&temp, sizeof(temp));
            temp = flipBytes(temp);
            fout << temp << '\n';
        }
    }
}
int UbyteExtractor::flipBytes(int i)
{
    unsigned char c1, c2, c3, c4;
    c1 = i & 255;
    c2 = (i >> 8) & 255;
    c3 = (i >> 16) & 255;
    c4 = (i >> 24) & 255;
    return ((int)c1 << 24) + ((int)c2 << 16) + ((int)c3 << 8) + c4;
}
Sample output snipet
0   0   0   0   0   0   303174147   447711358   2146959270  0   0   0   2589860894  4261281194  2900491773  1086583549  0   0   822083584   4261281262  4261281277  1381891069  2570322
 
     
    