-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,030
  • 21
  • 100
  • 124
Willem
  • 8,698
  • 16
  • 66
  • 90

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,030
  • 21
  • 100
  • 124
Tigran
  • 60,656
  • 8
  • 83
  • 120