I am having trouble with biHeight from the header info of bmp files. In the file small.bmp, from pset5, that is 3X3 pixels: biHeight has the value fffffffd. I would expect it to be the same as the value of biWidth: 3. Or if the header lines are counted that would be 53 more or some thing of the sort.

So I tested the cs50 implementation of the resize and got the following value of biWidth for a resize of X10: ffffffe2; and for a resize of X2: fffffffa.

Those values converted from hex to decimal are: X1: 4 294 967 293 X2: 4 294 967 290 X10: 4 294 967 266

I just don't get it.

Thanks for any help.

  • How are you obtaining that value for bi.biHeight? – wallek876 Feb 6 '15 at 12:18

That is because biHeight in this case is a negative number, and the representation in binary is made by the two's complement in this case, this can be a bit confusing but you can take a look at the link if you are interested.

As example the number -3, the one you are expecting, represented as a signed 32-bit integer in binary is:

11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111101

And when you transform this binary number to hexadecimal you obtain:


You don't need to interpret the bits of biHeihgt, you only need to do operations with it, like with any other variable, but considering that in some cases this value can be negative, and use the abs() function when needed.

  • A negative binary... and all this time I thought a signed binary had something to do with someone's signature. – Touten Feb 8 '15 at 8:21
  • Thank you for this clarification. I was losing my mind interpreting the hex value. – legalbot Jul 23 '19 at 22:04

From MSDN,


The height of the bitmap, in pixels. If biHeight is positive, the bitmap is a bottom-up DIB and its origin is the lower-left corner. If biHeight is negative, the bitmap is a top-down DIB and its origin is the upper-left corner.

The value fffffffd (hex) is 1111 1111 1111 1111 1111 1111 1111 1101 (bin). The two's complement for that value is 0000 0000 0000 0000 0000 0000 0000 0011 (bin) or 3 (dec). So fffffffd (hex) is basically -3 (dec).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .