vrutberg
vrutberg

Reputation: 2048

Reading and parsing the width/height property of a bitmap

I'm trying to write a bitmap (.bmp) parser/reader by reading raw bytes from the file and simply checking their values, and I've come across something I simply cannot wrap my mind around.

The image I'm trying to read is 512x512 pixels, and when I look at the width property (at 0x12 and 4 bytes onward) it says 00 02 00 00 (when viewed in a hex editor). I assume this is the same as the binary value 00000000 00000010 00000000 00000000. This somehow represents 512, I just cannot figure out the steps to get there.

So what I really need to know is how are integers represented binarily, and how do I parse them correctly? Any help is much appreciated. :)

Upvotes: 0

Views: 1029

Answers (2)

3lectrologos
3lectrologos

Reputation: 9662

What you are seeing in your hex editor is actually right. Just remember that bytes are in little endian order, so the value is actually 00 00 02 00 = 0x0200 = 512.

Upvotes: 2

Darin Dimitrov
Darin Dimitrov

Reputation: 1039338

Actually 0x200 in hex equals 512 in decimal. You may have the position of the width/height properties wrong.

Upvotes: 0

Related Questions