Logical Bitwise Operators

The following logical operators perform bitwise manipulation on integer operands. For example, if the value stored in X (in binary) is 001101 and the value stored in y is 100001, the statement

assigns the value 101101 to z. Logical (Bitwise) Operators

assigns the value 101101 to z. Logical (Bitwise) Operators


Operation Operand Types

Result Type



bitwise negation integer


not X


bitwise and integer


X and Y


bitwise or integer


X or Y


bitwise xor integer


X xor Y


bitwise shift left integer


X shl 2


bitwise shift rightinteger


Y shr I

The following rules apply to bitwise operators.

  • The result of a not operation is of the same type as the operand.
  • If the operands of an and, or, or xor operation are both integers, the result is of the predefined integer type with the smallest range that includes all possible values of both types.
  • The operations x shl y and x shr y shift the value of x to the left or right by y bits, which (if x is an unsigned integer) is equivalent to multiplying or dividing x by 2Ay; the result is of the same type as x. For example, if n stores the value 01101 (decimal 13), then n sh 1 returns 11010 (decimal 26). Note that the value of y is interpreted modulo the size of the type of x. Thus for example, if x is an integer, x shl 4 0 is interpreted as x shl 8 because an integer is 32 bits and 40 mod 32 is 8.
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook

Post a comment