Logo
RSS Feed

Algorithms

Sliding Window

Sliding window is a little different from two pointer. I personally found it hard to understand how, thus this article.

Sorting Algorithms

Bitwise Magic

*## Logical

AND

Zero N bits out

All you need to do, is to and it with a 0000 0000 mask (for a one byte value in this example).

Check if an integer is even

Mask it with 0000 0001. Even numbers have 0 at the end, and uneven - 1. anding an even number with 0000 0001 will result in 0 and anding an uneven - with 1.

Bit map

AND operation will be used to check if the given bit in the bit map was set already: if bit_vector & (1 << char_code). 1 « char_code basically does the following (using 8 bit value for simplicity). Say, we checking if either of the numbers appeared more than once in some data (numbers from 0 to 7).