I have binary file that is represented in hexa e.g
4d42 b666 000a 0000 0000 0036 0000 0028
The first 4 bytes represent value which i want to extract.
I know i can extract it right
std::ifstream is("img.bmp", std::ifstream::binary);
uint64_t data = 0;
is.read((char*)&data,4)
which would result in 3060157762
However using
unsigned char * test = new unsigned char [ 4 ];
is.read((char*)test , 4 );
uint64_t t = 0;
for( int i = 0; i < 4;i++){
t <<= 8; // 2 hexa symbols = 1 byte = 1 char = 8 bits
t|= test[i];
}
cout << t << endl;
this results in 1112368822
which obviously differ.
I wonder how could we achieve same result with second method? What are some bitwise tricks for this? I cannot think of anything besides the method i have shown.
Thanks for help.