OPENTech Guides

Bitwise operators are used to perform operations on individual bits of the operand or operands. Each bit in the operand will be either 0 or 1. Bitwise operators in C are:

Operator | Meaning |
---|---|

& | Bitwise AND; If both bits are 1 then result is 1 otherwise 0 |

| | Bitwise OR; If either one of the bit is 1 then result is 1 otherwise 0 |

^ | Bitwise Exclusive OR (XOR); If only one bit (NOT BOTH) is 1 then result is 1 otherwise 0 |

<< | Left Shift; Moves the bit pattern to the left |

>> | Right Shift; Moves the bit pattern to the right |

˜ | Complement; All 1 bits are changed to 0 and 0 bits are changed to 1 |

Consider two bit patterns

`a = 0000 1100`

b = 0000 0110

Operation | Meaning | Result |
---|---|---|

a & b | a AND b | 0000 0100 |

a | b | a OR b | 0000 1110 |

a ^ b | a XOR b | 0000 1010 |

a << 2 | a Left Shift 2 | 0011 0000 |

a >> 2 | a Right Shift 2 | 0000 0011 |

← Logical OperatorsSpecial Operators →