⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 20m 11s17 days 22 hours 20 minutes 11 seconds.
⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 20m 11s17 days 22 hours 20 minutes 11 seconds.

Sign in to watch this lesson
Algorithms - Bits and Number Theory · 4:44
An integer is a row of bits you can edit in one instruction: place values, two's complement (-13 = 1111 0011), shifts as multiplying and dividing by powers of two (and why -13 >> 1 is -7 but -13 / 2 is -6), and the mask idioms that set, clear, flip and test a bit. Then the trick behind most bit hacks, n & (n - 1), which clears the lowest set bit and gives the power-of-two test and Kernighan's popcount, plus C++20's <bit> functions and the pitfalls of 1 << 31 and __builtin_popcount on 64-bit values. It ends by counting the ones in 1..n in O(log n) by peeling off the top bit.