Your free access ends in 7 days — and you haven’t tried it yet. Watch one algorithm run, start to finish. It takes about two minutes.

Try one problem
0
Concept

Overview

AND · OR · XOR · shifts · the classic tricks
step 1 / 6
0
1
0
1
[0][1][2][3]
The bit toolkit
1// bit b worth 2^position
2x & y // 1 where both 1 (mask / test)
3x | y // 1 where either (set bits)
4x ^ y // 1 where differ (x^x=0, x^0=x)
5x << k // shift up (×2^k); 1<<k = bit-k mask
6n & (n-1) // clears the lowest set bit
state
  • value5
  • binary0101
  • places8 4 2 1

line 1Every integer is a string of BITS, each worth a power of two: positions (left→right here) are 8, 4, 2, 1. 5 = 0101 = 4 + 1. Bit tricks manipulate these directly with the operators &, |, ^, ~, and the shifts << / >>.