a & b = 0000 1100 a | b = 0011 1101 a ^ b = 0011 0001 ~a = 1100 0011 The following table lists the bitwise operators. Assume integer variable A holds 60 and variable B holds 13 then: Operator Description Example Binary AND Operator copies a & bit to the result if it exists in (A & B) will give 12 is 0000 1100 both operands. Binary OR Operator copies a | (A | B) will give 61 which is 0011 1101 bit if it exists in eather operand. Binary XOR Operator copies ^ the bit if it is set in one operand (A ^ B) will give 49 is 0011 0001 but not both. Binary Ones Complement ~ Operator is unary and has the (~A ) will give -60 which is 1100 0011 efect of 'flipping' bits. Binary Left Shift Operator. The left operands value is moved << A << 2 will give 240 which is 1111 0000 left by the number of bits specified by the right operand. Binary Right Shift Operator. The left operands value is >> moved right by the number of A >> 2 will give 15 which is 1111 bits specified by the right operand. 6.4 The Logical Operators The following lists the logical operators. Assume boolean variables A=true and variable B=false then: Operator Description Example Called Logical AND operator. If both the (A && B) is && operands are non zero then then condition false. becomes true. Called Logical OR Operator. If any of the two || operands are non zero then then condition (A || B) is true. becomes true.
a & b = 0000 1100 a | b = 0011 1101 a ^ b = 0011 0001 ~a = 1100 0011 The following table lists the bitwise operators. Assume integer variable A holds 60 and variable B holds 13 then: Operator Description Example & Binary AND Operator copies a bit to the result if it exists in both operands. (A & B) will give 12 is 0000 1100 | Binary OR Operator copies a bit if it exists in eather operand. (A | B) will give 61 which is 0011 1101 ^ Binary XOR Operator copies the bit if it is set in one operand but not both. (A ^ B) will give 49 is 0011 0001 ~ Binary Ones Complement Operator is unary and has the efect of 'flipping' bits. (~A ) will give -60 which is 1100 0011 << Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. A << 2 will give 240 which is 1111 0000 >> Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. A >> 2 will give 15 which is 1111 6.4 The Logical Operators The following lists the logical operators. Assume boolean variables A=true and variable B=false then: Operator Description Example && Called Logical AND operator. If both the operands are non zero then then condition becomes true. (A && B) is false. || Called Logical OR Operator. If any of the two operands are non zero then then condition becomes true. (A || B) is true.
Part-5-6-7-8.docx