Ben Pope wrote:
> Noah Roberts wrote:
> > Benjamin B. wrote:
> >> Hi everyone,
> >>
> >> in this thing I inherited there's a statement like this:
> >>
> >> a &= ~b;
> >>
> >> where a is an int and b has been declared this way:
> >>
> >> const b = 0x0002;
> >>
> >> and thus is probably an int as well.
> >>
> >> My question: What's the tilde doing there? Is that standard C++? What
> >> does it mean?
> >
> > If you are familiar with gates, which all these bitwise operators are,
> > it is NOT. NOT inverts its input so when it has power it is off, when
> > it doesn't it is on. Power is 1, no power is 0. Output is 0 where
> > there is a 1 and 1 where there is a 0 in the input.
>
> I think you are talking about ! (logical NOT), it is in the same family as:
> &&
> ||
> ==
> !=
> <
> >
> <=
> >=
No, but those are boolean operators that behave in similar ways. If
you wish to think of them in those terms as well it might help. At
least &&, ||, and ! may very well be implemented as gates.
>
> operator~ is bitwise NOT or complement. It applies a NOT to each and
> every bit, it is in the same family as:
> &
AND
> |
OR
> ^
NAND
> <<
> >>
I can't think of any gate that will perform these functions.
|