語言

Integer.NumberOfLeadingZeros(Int32) 方法

定義

回傳在指定 int 值的補數二進位表示中,最高階(「最左」)一位元之前的零位元數。

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

參數

i
Int32

要計算的前置零點數的值

傳回

在兩個 int 補數值的補數二進位表示中,最高階(「最左」)一位元之前的零位元數,若值為零則為 32。

屬性

備註

回傳在指定 int 值的補數二進位表示中,最高階(「最左」)一位元之前的零位元數。 若指定值的二補數表示中沒有一位元,也就是說,若值等於零,則回傳 32。

請注意,此方法與對數底制 2 密切相關。 對所有正int值 x: <ul><li>floor(log<sub>2</sub>(x)) = 31 - numberOfLeadingZeros(x)<li>ceil(log<sub>2</sub>(x)) = 32 - numberOfLeadingZeros(x - 1)</ul>

已在1.5中新增。

Java 文件 java.lang.Integer.numberOfLeadingZeros(int)

本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。

適用於