Share via


Integer.NumberOfLeadingZeros(Int32) Method

Definition

Returns the number of zero bits preceding the highest-order ("leftmost") one-bit in the two's complement binary representation of the specified int value.

[Android.Runtime.Register("numberOfLeadingZeros", "(I)I", "")]
public static int NumberOfLeadingZeros (int i);
[<Android.Runtime.Register("numberOfLeadingZeros", "(I)I", "")>]
static member NumberOfLeadingZeros : int -> int

Parameters

i
Int32

the value whose number of leading zeros is to be computed

Returns

the number of zero bits preceding the highest-order ("leftmost") one-bit in the two's complement binary representation of the specified int value, or 32 if the value is equal to zero.

Attributes

Remarks

Returns the number of zero bits preceding the highest-order ("leftmost") one-bit in the two's complement binary representation of the specified int value. Returns 32 if the specified value has no one-bits in its two's complement representation, in other words if it is equal to zero.

Note that this method is closely related to the logarithm base 2. For all positive int values x: <ul> <li>floor(log<sub>2</sub>(x)) = 31 - numberOfLeadingZeros(x)<li>ceil(log<sub>2</sub>(x)) = 32 - numberOfLeadingZeros(x - 1)</ul>

Added in 1.5.

Java documentation for java.lang.Integer.numberOfLeadingZeros(int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to