When you're talking about bitwize `and`, you're talking about performing a binary operation on each individual bit in the information - you're modifying the value, content or data. Each individual `bit` in the value, when represented in binary notation, is `and'ed` with the bits in the mask you provide. There must be a 1 set in the mask and a 1 set in the value in order for that 1 to remain in the value, otherwise it is set to 0. This `masks in or out` different bits of the value. This is `bitwize and` - to do with the bits in the value.
A logical and is to do with boolean expressions where you're talking about `this expression is true` and also `that expression is true`. It's the logical combination of more than one expression. In that case the total value of one expression has to be true AND the total value of the other expression(s) has to be true, in order for the *overall* total expression to be true. It's more a matter of boolean logic than what the actual content of each expression is.
Bitwize AND ("&") works on the individual bits in a the value of a single expression.
Logical AND ("and") works on comparing more than one expression to each other.
Consider them micro and macro levels. Bitwize is the micro level, logical is the macro level.
You use bitwize and to mask one value against another, typically to set certain bits in the value to 0 so that you can isolate only the part you want to screen out unwanted data from within a value. You use logical and to then decide whether to go ahead with a *condition* based on all the parts of an expression being true (where true means nonzero, right?)
So it's handy to distinguish between the two types. You need to know whether you are working on the bits within an expression or comparing more than one expression.
They could have it so that both use the "and" keyword and for some people that is sufficient clarity. For others it's nice to distinguish the subtle difference between the two.
Same goes for `or` - bitwize OR ("|") means if the bits in one value are set OR the bits in the other value are set, they remain set, otherwise they become 0 - on a binary leve. The logical OR means you are comparing the result of two or more individual expressions/values and if ANY of those expressions are true in boolean terms then the overall expression is true.
If you had only an "and" and "or" keyword, code would look like this:
If ((a and b) and (c and d)) or (f or (g and m))
rather than
If ((a & b) and (c & d)) or (f | (g & m))
or
If ((a=true and b=true) & (c=true and d=true)) | (f=true or (g=true and m=true)
See how there can be lots of different interpretations, you don't really know whether you are talking about `anding` the values together or treating them as boolean logic. There are two distinct functionalities here - modifying the value and checking whether the value is true. I think it's good to have two distinguishing keywords cus then you know exactly what is happening.
A logical and is to do with boolean expressions where you're talking about `this expression is true` and also `that expression is true`. It's the logical combination of more than one expression. In that case the total value of one expression has to be true AND the total value of the other expression(s) has to be true, in order for the *overall* total expression to be true. It's more a matter of boolean logic than what the actual content of each expression is.
Bitwize AND ("&") works on the individual bits in a the value of a single expression.
Logical AND ("and") works on comparing more than one expression to each other.
Consider them micro and macro levels. Bitwize is the micro level, logical is the macro level.
You use bitwize and to mask one value against another, typically to set certain bits in the value to 0 so that you can isolate only the part you want to screen out unwanted data from within a value. You use logical and to then decide whether to go ahead with a *condition* based on all the parts of an expression being true (where true means nonzero, right?)
So it's handy to distinguish between the two types. You need to know whether you are working on the bits within an expression or comparing more than one expression.
They could have it so that both use the "and" keyword and for some people that is sufficient clarity. For others it's nice to distinguish the subtle difference between the two.
Same goes for `or` - bitwize OR ("|") means if the bits in one value are set OR the bits in the other value are set, they remain set, otherwise they become 0 - on a binary leve. The logical OR means you are comparing the result of two or more individual expressions/values and if ANY of those expressions are true in boolean terms then the overall expression is true.
If you had only an "and" and "or" keyword, code would look like this:
If ((a and b) and (c and d)) or (f or (g and m))
rather than
If ((a & b) and (c & d)) or (f | (g & m))
or
If ((a=true and b=true) & (c=true and d=true)) | (f=true or (g=true and m=true)
See how there can be lots of different interpretations, you don't really know whether you are talking about `anding` the values together or treating them as boolean logic. There are two distinct functionalities here - modifying the value and checking whether the value is true. I think it's good to have two distinguishing keywords cus then you know exactly what is happening.