Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Bitwise operators work on individual bits of integers. They are extremely fast and essential for competitive programming.
&AND1 if both bits are 15 & 3 = 1101 & 011 = 001|OR1 if either bit is 15 | 3 = 7101 | 011 = 111^XOR1 if bits differ5 ^ 3 = 6101 ^ 011 = 110~NOTFlips all bits~5 = -6~00000101<<Left ShiftShifts bits left (×2)3 << 2 = 12011 → 1100>>Right ShiftShifts bits right (÷2)12 >> 2 = 31100 → 011n & 1 // 0=even, 1=oddx << nx >> na^=b; b^=a; a^=b;n & (n-1) == 0