Following will show you bitwise And & , OR | and XOR ^ operations, And & will copy a bit to the result if it exists in both operands:
Code:
main()
{
/* Binary Values */
unsigned int a = 60; /* 60 = 0011 1100 */
unsigned int b = 13; /* 13 = 0000 1101 */
unsigned int c = 0;
c = a & b; /* 12 = 0000 1100 */
}
OR | will copy a bit if it exists in eather operand:
Code:
main()
{
/* Binary Values */
unsigned int a = 60; /* 60 = 0011 1100 */
unsigned int b = 13; /* 13 = 0000 1101 */
unsigned int c = 0;
c = a | b; /* 61 = 0011 1101 */
}
XOR ^ copies the bit if it is set in one operand (but not both)
Code:
main()
{
/* Binary Values */
unsigned int a = 60; /* 60 = 0011 1100 */
unsigned int b = 13; /* 13 = 0000 1101 */
unsigned int c = 0;
c = a ^ b; /* 49 = 0011 0001 */
}