used as an index into hash table BitPositionLookup. The selected hash table value is the bit index of the least significant set bit in v. The following example determines the index of the most significant bit set in a 32 bit unsigned integer: uint32_t keepHighestBit(uint32_t n) { n |= (n >> 1); n |= (n >> 2); n |= (n >> 4); n |= (n >> 8); n |= (n >> 16); return n - (n >> 1); } uint8_t highestBitIndex(uint32_t v) { static const uint8_t BitPositionLookup[32] = { // hash table 0, 1, 16, 2, 29, 17, 3, 22, 30, 20, 18, 11, 13, 4, 7, 23, 31, 15, 28, 21, 19, 10, 12, 6, 14, 27, 9, 5, 26, 8, 25, 24, }; return BitPositionLookup[(keepHighestBit(v) * 0x06EB14F9U) >> 27]; } In the above example an alternative de Bruijn sequence (0x06EB14F9U) is used, with corresponding reordering of array values. The choice of this particular de Bruijn sequence is arbitrary, but the hash table values must be ordered to match the chosen de Bruijn sequence. The keepHighestBit() function zeros all bits except the most-significant set bit, resulting in a value which is a power of 2, which is then processed as in the previous example. Brute-force attacks on locks A de Bruijn sequence can be used to shorten a brute-force attack on a PIN-like code lock that does not have an "enter" key and accepts the last n digits entered. For example, a digital door lock with a 4-digit code (each digit having 10 possibilities, from 0 to 9) would have B (10, 4) solutions, with length . Therefore, only at most (as the solutions are cyclic) presses are needed to open the lock, whereas trying all codes separately would require presses. f-fold de Bruijn sequences f-fold n-ary de Bruijn sequence''' is an extension of the notion n-ary de Bruijn sequence, such that the sequence of the length contains every possible subsequence of the length n exactly f times. For example, for the cyclic sequences 11100010 and 11101000 are two-fold binary de Bruijn sequences. The number of two-fold de Bruijn sequences, for is , the other known numbers are , , and . De Bruijn torus A de Bruijn torus is a toroidal array with the property that every k-ary m-by-n matrix occurs exactly once. Such a pattern can be used for two-dimensional positional encoding in a fashion analogous to