The symbol for this operator is &. This operator performs AND operation on the individual bits of the numbers. This operator produces 1 if both operands are 1, otherwise it will produce 0. To understand AND operator, see the truth table
This operator is presented by the pipe symbol (|). This operator performs OR operation on the bits of the numbers. This operator produces 0, if both operands are 0, otherwise it produces 1. See the truth table
This operator is represented by the symbol (^). This operator performs exclusiveOR operation on the bits of the numbers. To understand the XOR operation see the following truth table
This operator is used for shifting the bits left. It requires two operands. The left operand is the operand whose bits are shifted and right operand indicates the number of bits to be shifted. On shifting the bits left, an equal number of bit position on the right are vacated. These positions are filled in with 0 bits. For example, let a=5, consider the statement
The value in the integer a is shifted to the left by three bit positions. The result is assigned to y. Since the value of a is 0000 0000 0000 0101 after the execution the value of y will be 0000 0000 0010 1000 which is nothing but 40 in decimal
The effect of shifting a variable to the left by one bit position is to multiply it by 2. In this example, x is shifted left by 3 positions, which is equivalent to multiplying x by 2*2*2 . since the initial value of x is 5, the value assigned to y is 5*8=40.
This operator is similar to the left shift operator, except that it shifts the bits to the right side. On shifting the bits right , an equal number of bit position on the left are vacted. Consider the following example.
Hence the shifting to right by 2bit "0000 0000 0000 0001" =4. Since the initial value of x is 5, shifting to the right by 2bit positions will give the value 1 (5/4=1).
This operator also shifts the bits of the number towards right a specified number of positions. But it stores 0 in the sign bit. The symbol for this operator is >>>. Since it always fills 0 in the sign bit, it is called Zero fill right shift operator. If we apply >>> on a positive number, it gives the same output as that of >>. But in case of negative number, the output will be positive since the sign bit is replaced by a 0.
y=1❮ Previous Next ❯