0

I was wondering why binary numbers can't be used with bitwise operators?

//works
msgSize = (*(msgbody+1) & 0x80)?*(msgbody+5):*(msgbody+3); 

//doesn't compile
msgSize = (*(msgbody+1) & 0b10000000)?*(msgbody+5):*(msgbody+3); 
Cœur
  • 34,719
  • 24
  • 185
  • 251
bioffe
  • 6,021
  • 2
  • 46
  • 63

1 Answers1

1

Binary literals aren't supported in C; If they're available, they're an extension. I would suggest that your compiler is emitting an error because it doesn't recognise the binary literal 0b10000000. Hence, your compiler probably emits an error on this, too:

int main(void) {
    int msgSize = 0b10000000;
    return 0;
}

I would suggest using 0x80 or 1 << 7 instead.

autistic
  • 14,835
  • 2
  • 35
  • 78