-1

Possible Duplicate:
Why '&&' and not '&'?

When would I use a bit-wise AND and normal AND?

I read the bit-wise AND is good for applications that have a memory limit.

Which one will be the best to use then, overall?

if (true & false)
{

}

or

if (true && false)
{

}

Wouldn't it be better to always use a bit-wise AND then?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Willem
  • 9,166
  • 17
  • 68
  • 92

1 Answers1

1

Bitwise AND (&) is a bitwise operation on both operands. && instead, is a logical AND operation.

I read the bit-wise AND is good for applications that have a memory limit

This assumption is not correct. I can say that bitwise can be used in intensive calculus, for example in a CAD application kernel's drawing procedure when you need to divide an absolute number by 2 (say), instead of using ordinary division which is slow, we use bitwise shift >>. But these are extreme conditions and 99% of cases none will approve use of such techniques.

So it's basically about performance improvement and not memory.

They are completely different.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tigran
  • 61,654
  • 8
  • 86
  • 123