Here is the function I'm using to test if the first four bytes of the buffer match the header file for a .jpg image. When I compile the program (in its very early stages) it reports that the function valid_start will always return true. Is it the BYTE designation that is causing problems?

bool valid_start(BYTE buffer[]) { if(buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && buffer[3] & 0xf00) == 0xe0) return true; else return false; }

  • Mismatch in parentheses (you have more ) than (). And check out the {} button in the editor.
    – Blauelf
    May 14, 2019 at 9:47
  • What's the actual code you compiled? Edit it into your question using the {} button after selecting the code.
    – Blauelf
    May 14, 2019 at 11:52

1 Answer 1


buffer[3] is a BYTE, an integer of value 0 to 255, eight bits. Now 0xf00 is 0b111100000000, having a 0 for each bit of buffer[3]. As & results in a number that has a binary 1 wherever both inputs have one, the result of buffer[3] & 0xf00 is always 0.

You meant 0xf0, not 0xf00.

And the code you posted won't compile for missing ( somewhere, plus if I inserted it right before buffer[3], which seems most appropriate to me, I have the function return false all the time, not true as you claimed.

You must log in to answer this question.

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