Computer Science Canada "Not" |
Author: | rar [ Wed Oct 07, 2009 7:41 pm ] |
Post subject: | "Not" |
What is the difference between '~' and '!' in C? I've been reviewing my notes for an upcoming quiz and was not aware there was a difference... |
Author: | saltpro15 [ Wed Oct 07, 2009 7:49 pm ] | ||
Post subject: | RE:"Not" | ||
~ can be used as a destructor right? like
|
Author: | bbi5291 [ Wed Oct 07, 2009 7:52 pm ] |
Post subject: | Re: "Not" |
The ! operator is a logical negation. Applied to zero (false), it yields one (true). Applied to any nonzero value (true), it yields zero (false). The ~ operator on the other hand is a bitwise negation. When ~ is applied to an integer, every bit in the integer's binary representation is flipped. |
Author: | DtY [ Wed Oct 07, 2009 7:54 pm ] |
Post subject: | RE:"Not" |
! is logical, ~ is bitwise, ! is the not of || and &&, ~ is the not of | and &. For example, (I don't know if 0b works in C, but I'll assume it does, it means binary number, assume 8 bit) !0b00000001 = 0b00000000 ~0b00000001 = 0b11111110 !0b00000000 = 0b00000001 ~0b00000000 = 0b11111111 |