Bit masking question

I have a 32 bit status flag. The first 8 bits (0-7) signify a warning if any are set, while the higher 24 bits (8-31) signify an error if any are set.

I wrote the following:
1
2
3
4
5
6
7
8
9
  if (*status == 0) {
    *level = 0;  // all OK
  }
  else if (*status && 0xFFFFFF00) {
    *level = 2;  // error
  }
  else {
    *level = 1;  // warning
  }

The error / warning assignments for level are not coming out correctly.

For example: let's say I have status set to 32 = 0x00000020 (ie. warning), then (status && 0xFFFFFF00) should be 0, by doing a bitwise and on all 32 bits. But when I view this in the debugger it says (status && 0xFFFFFF00) is true, resulting in the middle block being executed. But true is non-zero in C. What's going on?
You're using "&&" which is logical and, that means anything apart from 0 will be true.
What you meant to use is "&" bitwise and, which will compare individual bits.
ok thanks
Topic archived. No new replies allowed.