PDA

View Full Version : A simple question



Lee_Jennifer_82
12-16-2015, 02:56 PM
Hello, I've a simple question. I'm going through some code related with writing a bmp image file.

In the following code, what does 'filesize>>8' imply? How is it used in a bmp file?


bmpfileheader[ 2] = (unsigned char)(filesize );
bmpfileheader[ 3] = (unsigned char)(filesize>> 8);
bmpfileheader[ 4] = (unsigned char)(filesize>>16);
bmpfileheader[ 5] = (unsigned char)(filesize>>24);



Thanks.

Lee_Jennifer_82
12-16-2015, 03:23 PM
I understand, this is just offset in the bmp file header.

Agent D
12-16-2015, 11:30 PM
The file size in the image is little endian (https://en.wikipedia.org/wiki/Endianness). This code stores the integer as little endian irregardless of the
machines actual endianness (https://en.wikipedia.org/wiki/Endianness).

The code assumes that a character has 8 bits. The first line extracts the first byte of the integer, the
second line the next higher byte (shifting it to the right by 8 bits and cutting the rest off), the third line
the next higher bytes (shifting it right by 16, cutting the rest of) and the last line extracts the highest
byte.