Thursday, March 08, 2007

Bitwise Operators

Bitwise operators in Indonesian is also called as "Gerbang Logika" where the operators consist of NOT, AND, OR and XOR.

NOT
NOT is also called as complement or negation. It gives the negation value. For example :

NOT TRUE is FALSE
NOT FALSE is TRUE

AND
AND operator is very easy to remember, it only returns TRUE if TRUE AND TRUW. For example :

TRUE AND TRUE is TRUE
TRUE AND FALSE is FALSE
FALSE AND TRUE is FALSE
FALSE AND FALSE is FALSE

OR
OR operator gives TRUE when one of the component is TRUE. For example :

TRUE OR TRUE is TRUE
TRUE OR FALSE is TRUE
FALSE OR TRUE is TRUE
FALSE OR FALSE is FALSE


XOR
XOR means Exclusive OR. Why Exclusive? Because XOR returns TRUE only when the components is different. For example :

TRUE XOR TRUE is FALSE
TRUE XOR FALSE is TRUE
FALSE XOR TRUE is TRUE
FALSE XOR FALSE is FALSE

XOR also can be formulated by AND, OR and NOT operands, to be:
((Component1 AND NOT(Component2)) OR Component2 AND NOT(Component1)))

That's all folks, the other is only combination of the fourth of them.

No comments: