
-----------------------------------
rar
Wed Oct 07, 2009 7:41 pm

&quot;Not&quot;
-----------------------------------
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...

-----------------------------------
saltpro15
Wed Oct 07, 2009 7:49 pm

RE:&quot;Not&quot;
-----------------------------------
~ can be used as a destructor right?

like
[code]
Queue();
~Queue();
[/code]

-----------------------------------
bbi5291
Wed Oct 07, 2009 7:52 pm

Re: &quot;Not&quot;
-----------------------------------
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.

-----------------------------------
DtY
Wed Oct 07, 2009 7:54 pm

RE:&quot;Not&quot;
-----------------------------------
! 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
