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
Post a Comment