c - difference between similar bitwise operators -


in refereing bit-wise operators, difference between ! , ~ ? feel both flip bits, 1 maybe adds 1 final answer?

~0xc4  compared  !0xc4 

thanks!

! not bitwise operator, it's boolean operator.

the boolean operators operate on truth values, int. non-zero value true, while 0 false. result 1 true, 0 false.

  • ! boolean not
  • && boolean and
  • || boolean or

these ones used in e.g. if since needs boolean value. boolean and/or operators short-circuiting, means stop evaluating when result known. good, means 1 || crash_and_burn() never crash , burn.

but bitwise operators operate on each bit of integer-typed argument(s), after promotions , such of course.

  • ~ bitwise not
  • & bitwise and
  • | bitwise or
  • ^ bitwise exlusive-or (xor)

the bitwise operators (of course) not short-circuiting, wouldn't make sense since operate on pairs of bits. note while there ^ bitwise operator, there no ^^ boolean xor operator.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -