Java.lang.Long.numberOfTrailingZeros() 方法
描述
java.lang.Long.numberOfTrailingZeros() 方法返回指定 long 值的二进制补码表示中最低位("最右边")一位之后的零位数。 如果指定的值在其二进制补码表示中没有一位,则返回 64,换句话说,如果它等于 0。
声明
以下是 java.lang.Long.numberOfTrailingZeros() 方法的声明。
public static int numberOfTrailingZeros(long i)
参数
i − 这是 long 值。
返回值
此方法返回指定 long 值的二进制补码表示中最低位("最右边")一位之后的零位数,如果该值等于 0,则返回 64。
异常
NA
示例
下面的例子展示了 java.lang.Long.numberOfTrailingZeros() 方法的使用。
package com.tutorialspoint; import java.lang.*; public class LongDemo { public static void main(String[] args) { long l = 210; System.out.println("Number = " + l); /* returns the string representation of the unsigned long value represented by the argument in binary (base 2) */ System.out.println("Binary = " + Long.toBinaryString(l)); /* returns a long value with at most a single one-bit, in the position of the lowest-order ("rightmost") one-bit in the specified int value.*/ System.out.println("Lowest one bit = " + Long.lowestOneBit(l)); /*returns the number of zero bits preceding the highest-order ("leftmost")one-bit */ System.out.print("Number of leading zeros = "); System.out.println(Long.numberOfLeadingZeros(l)); /* returns the number of zero bits following the lowest-order ("rightmost") one-bit */ System.out.print("Number of trailing zeros = "); System.out.println(Long.numberOfTrailingZeros(l)); } }
让我们编译并运行上面的程序,这将产生下面的结果 −
Number = 210 Binary = 11010010 Lowest one bit = 2 Number of leading zeros = 56 Number of trailing zeros = 1