rama1001 said:
Hi,
I had read some descriptions about these on web but i fell, both doing same thing. More, i observe these are changing language to language. Can any tell me straight difference with example.. that would be helpful to me.
The notions of the logical and bitwise AND occur in some languages, the most commonly known being the imperative C language. To be honest, most of the confusion stems from that these languages are not very well designed for humans but often inherit qualia from the underlying machine, more specific, the machine language they are translated to.
Having stated that, the notions of the logical and bitwise and are not very difficult to understand in a layman's manner.
The bitwise AND is an operator which takes two series of bits and evaluates both bit patterns by AND-ing the bits in their respective positions. E.g., 1101 AND 0110 becomes 0100, that value may latter have a logical meaning (TRUE or FALSE) in the given language.
The logical AND operates on two 'logical' values which may be understood to be individual bits. I.e., FALSE AND TRUE evaluates to FALSE. Moreover, procedures which evaluate to boolean values can be combined in this manner. E.g., f_returning_FALSE() AND g_returning_TRUE() is understood to denote the boolean value FALSE.
Because the logical AND is often used in conditional statements, usually the logical AND is evaluated in a left-to-right manner. E.g., in the example 'f_returning_FALSE() AND g_returning_TRUE()' only the first procedure call is made since that call will return FALSE, and therefor the whole clause must return FALSE, and the second call doesn't need to be made. This is often a source for confusion and errors.
In short, bitwise AND is the AND operator on series of bits, logical AND is the AND operator on statements returning boolean values with a left-to-right evaluation order.
EDIT: These operators in C are denoted as & (bitwise) and && (logical). Since they are only one character apart, and behave in very different manners, this is another source for common errors.