# MATH_CountLeadingZeros

## Syntax

      #include <nitro/math.h>

      u32 MATH_CountLeadingZeros( u32 x );
      u32 MATH_CLZ( u32 x );

## Arguments

x | Numeric value to evaluate

## Return Values

The number of sequential 0 bits, starting from the highest-order bit.

## Description

Scans the data of a 32-bit quantity and reports the number of sequential bits that are set to 0 beginning at the highest-order bit. For example, a value of `0x80000000` returns 0, and a value of 0 returns 32. The internal implementation is such that the function is an inline function wrapping a `CLZ` command that can be used with ARM9 ARM code. It is expanded as one instruction by the compiler. In ARM7 and ARM9 THUMB code, the standard function is called.
For this reason, if your program internally switches between ARM and THUMB code, do not use `#pragma thumb on`. Instead use `#include <twl/code16.h>`.
See the Description of Header Files page for a description of `code16.h`.

`MATH_CLZ` is another name for the `MATH_CountLeadingZeros` function.

To count the number of consecutive 0's from the end, use the `MATH_CountTrailingZeros` function.

## See Also

`MATH_CountTrailingZeros`
`MATH_ILog2`

## Revision History

2009/04/28 Described the method for switching to THUMB mode.
2006/01/10 Added missing links.
2005/12/22 Added a link to the `MATH_CountTrailingZeros` function.
2005/06/02 Corrected "&" notation.
2004/12/14 Initial version.

CONFIDENTIAL