How to compute the number of trailing zeros?

Given the binary representation of some integer, a typical problem is to determine the number of trailing zeros. This HOWTO will show you how to accomplish the task in constant time. The reader is assumed to have experience with the C programming language, though the methods presented throughout this document can easily be applied to other languages as well. You'll learn a little bit about math (de Bruijn sequences) and computers (Two's complement gimmicks).

The HOWTO is available in the following formats:

Enjoy!