#include #include // This program reads the Bit Data Offset field. // Note that b0 is the least significant digit, // occupying the lowest address in memory // For further reference, please read: // http://www.cs.umass.edu/~verts/cs32/endian.html // Thanks to Darrell Grainger for the contribution // in the newsgroup with this link int main(int argc, char* argv[]) { fstream fs; unsigned char b0, b1, b2, b3; int value; // Open as binary fs.open("1.bmp", ios::in|ios::binary); // Positions the get pointer to read the "Offset" field fs.seekg(2 + 4 + 4); // fs.seekg(2); // For the file size (24750) - Comment the previous line // Reads the next four bytes // The value of b0..b3 are already in decimals fs.read((char*)&b0, sizeof(char)); fs.read((char*)&b1, sizeof(char)); fs.read((char*)&b2, sizeof(char)); fs.read((char*)&b3, sizeof(char)); // Calculates the value value = b0 + 256*b1 + 256*256*b2 + 256*256*256*b3; cout << "Bit Data Offset = " << value << endl; fs.close(); cout << "Press any key to close" << endl; getchar(); return 0; }