What are the Bit Operators?

What are the Bit Operators?

Bit operators are different frm logical operator. So,don't confuse with them.The keyword TRUE signifies a true bit (or bits) that is set to one,
and FALSE signifies a bit (or bits) that is set to zero. 
Some Bitwise Operators are given below:

&: Performs a bitwise AND operation. If both operands are TRUE, the result is TRUE; otherwise, the result is FALSE.
|: Performs a bitwise OR operation. If either operand is TRUE, the result is TRUE; otherwise, the result is FALSE.
^: Performs a bitwise exclusive OR operation. If both operands are TRUE or both operands are FALSE, the result is FALSE. The result is TRUE if one operand is TRUE and the other is FALSE. Exclusive OR is used to test to see that two operands are different.
<<: Shifts the X operand, Y operand bits to the left. For example, (1 << 4) returns a value of 8. In bits, (0001 << 4) results in 1000. New
positions to the left are filled with zeroes. This is a quick way to multiply by 2, 4, 8, and so on.  
>>: Shifts the X operand, Y operand bits to the right. For example, (8
>> 4) returns a value of 1. In bits, (1000 >> 4) results in 0001. New positions to the right are filled with ones or zeroes, depending on the value and whether the operand being shifted is signed. This is a quick way to divide by 2, 4, 8, and so on.
// Using a bitwise AND:
if (x & y)
{
// With x == 1, and y == 2, this will NEVER be TRUE.
}

By:Vivek Kr. Agarwal
Date:2007-01-09 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related C Subjective Links

C Subjective interview questions and answers for experienced and fresher