def nlz(x):
    """ Get the number of leadings zeros in a 32 bit word.

    >>> nlz (0)
    32
    >>> nlz (0x1)
    31
    >>> nlz (0xFF)
    24
    >>> nlz (0xFFFFFFFF)
    0

    See: http://www.hackersdelight.org/hdcodetxt/nlz.c.txt

    See: [Warren2013]_ pages 99ff
    """
    n = 32
    for shift in (16, 8, 4, 2, 1):
        y = x >> shift
        if y != 0:
            n = n - shift
            x = y
    return n - x
