整数类numberOfLeadingZeros()方法 (Integer class numberOfLeadingZeros() method)

  • numberOfLeadingZeros() method is available in java.lang package.

    在java.lang包中提供了numberOfLeadingZeros()方法

  • numberOfLeadingZeros() method is used to returns the number of 0's bits preceding the leftmost one bit in the 2's complement of the given parameter [value] of integer type. Otherwise, it returns 32 if the given parameter value is 0.

    numberOfLeadingZeros()方法用于返回整数类型的给定参数[value]的2的补码中最左一位之前的0位数。 否则,如果给定参数值为0,则返回32。

  • numberOfLeadingZeros() method is a static method, it is accessible with the class name too and if we try to access the method with the class object then also we will not get an error.

    numberOfLeadingZeros()方法是一个静态方法,也可以使用类名进行访问,如果我们尝试使用类对象访问该方法,那么也不会出错。

  • numberOfLeadingZeros() method does not throw an exception.

    numberOfLeadingZeros()方法不会引发异常。

Syntax:

句法:

    public static int numberOfLeadingZeros (int value);

Parameter(s):

参数:

  • int value – represents the integer value to be parsed.

    int value –表示要解析的整数值。

Return value:

返回值:

The return type of this method is int, if the given argument is non-zero then, it returns the number of 0's bits preceding the leftmost one bit of the given int value. Else, if the given argument is zero then, it returns the value 32.

此方法的返回类型为int ,如果给定参数不为零,则它返回给定int值的最左一位之前的0位数。 否则,如果给定参数为零,则返回值32。

Example:

例:

// Java program to demonstrate the example
// of numberOfLeadingZeros (int value) method of Integer class
public class NumberOfLeadingZerosOfIntegerClass {public static void main(String[] args) {int value1 = 1296;
int value2 = 0;
// It returns the string representation of the given unsigned
// integer value denoted by the argument in binary by calling
// Integer.toBinaryString(value1)
System.out.println("Integer.toBinaryString(value1): " + Integer.toBinaryString(value1));
// It returns the string representation of the given unsigned
// integer value denoted by the argument in binary by calling
// Integer.toBinaryString(value2)
System.out.println("Integer.toBinaryString(value2): " + Integer.toBinaryString(value2));
// It returns the number of 0's bits preceding the leftmost side
// one bit in the given argument 'value' by calling
// Integer.numberOfLeadingZeros(value1)
System.out.println("Integer.numberOfLeadingZeros(value1): " + Integer.numberOfLeadingZeros(value1));
// It returns the value 32 because the value of
// the given argument is zero
System.out.println("Integer.numberOfLeadingZeros(value2): " + Integer.numberOfLeadingZeros(value2));
}
}

Output

输出量

Integer.toBinaryString(value1): 10100010000
Integer.toBinaryString(value2): 0
Integer.numberOfLeadingZeros(value1): 21
Integer.numberOfLeadingZeros(value2): 32

翻译自: https://www.includehelp.com/java/integer-class-numberofleadingzeros-method-with-example.aspx

Java Integer类numberOfLeadingZeros()方法的示例相关推荐

  1. java中intvalue方法作用_Java Integer类intValue()方法及示例

    整数类intValue()方法intValue()方法在java.lang包中可用. intValue()方法用于返回此Integer对象表示的值,该值转换为int类型(通过强制转换). intVal ...

  2. java annotation class,Java Class类 isAnnotation()方法及示例

    Class类isAnnotation()方法isAnnotation()方法在java.lang包中可用. isAnnotation()方法用于检查此Class对象是否表示注释类型. isAnnota ...

  3. java字符类型的返回值,Java字符类isWhitespace()方法及示例

    Character 类isWhitespace()法isWhitespace()方法在java.lang包中可用. isWhitespace()方法用于检查给定的char值是否为空格,但是它包含空格中 ...

  4. java日历类add方法_Java日历computeTime()方法及示例

    java日历类add方法 日历类computeTime()方法 (Calendar Class computeTime() method) computeTime() method is availa ...

  5. java日历类add方法_Java日历computeFields()方法及示例

    java日历类add方法 日历类的computeFields()方法 (Calendar Class computeFields() method) computeFields() method is ...

  6. java日历类add方法_Java日历setFirstDayOfWeek()方法与示例

    java日历类add方法 日历类setFirstDayOfWeek()方法 (Calendar Class setFirstDayOfWeek() method) setFirstDayOfWeek( ...

  7. java日历类add方法_Java日历setMinimalDaysInFirstWeek()方法与示例

    java日历类add方法 日历类setMinimalDaysInFirstWeek()方法 (Calendar Class setMinimalDaysInFirstWeek() method) se ...

  8. java散列法的运用实例,Java HashMap compute() 使用方法及示例

    Java HashMap compute() 使用方法及示例 Java HashMap compute()方法计算一个新值,并将其与哈希映射中的指定键相关联. compute()方法的语法为: has ...

  9. Java——String类的方法

    Java--String类的方法 String str1 = "abc" 与String str2 = new String("abc")有什么区别? 字符串常 ...

最新文章

  1. win10未开启没有运行无线服务器,win10系统提示共享无线自动配置服务没有自动运行的解决办法...
  2. [python] Kmeans文本聚类算法+PAC降维+Matplotlib显示聚类图像
  3. 卷积核和全连接层的区别_「动手学计算机视觉」第十六讲:卷积神经网络之AlexNet...
  4. centos关于”running yum-complete-transaction first...
  5. 9.霍夫变换:圆——圆的算法、投票使用技巧、优点和缺点_2
  6. iphone换机数据迁移_怎么一键换机?换新机迁移数据必看教程!
  7. docker容器和宿主机时间不一致的问题
  8. 推荐3个免费开源的加密软件,知乎高赞
  9. Unity3D Demo
  10. 基于STM32F103C8T6的74HC595驱动8位数码管模块学习
  11. 李沐老师 PyTorch版——线性回归 + softmax回归的简洁实现(3)
  12. 计算机主板结构分为at,2.2.1 计算机主板结构(1)
  13. 语c和c语言,00后黑话等级测试,你能看懂几句?
  14. 格美家具网站项目总结
  15. 7-6 计算存款利息 (10分)
  16. R语言并行计算RC~bray-curtis~距离
  17. mysql server mirro_Docker下安装MySQL Server镜像
  18. python把四个图画在一个窗口_Python 多个图同时在不同窗口显示的实现方法
  19. 【国内生态学研究机构介绍系列】之北京大学
  20. html5读取ic卡,企业员工IC卡考勤系统(IC卡读写)

热门文章

  1. linux 系统调用时怎么知道当前上下文属于那个进程,linux – 编写系统调用来计算进程的上下文切换...
  2. java拼三级魔方_魔方秘籍(详细解法)《三阶》
  3. mysql给字段添加描述_用sql 语句给字段添加描述
  4. sql同时操作两列_怎么在两列同时筛选数据库
  5. 模型压缩 相关文章解读
  6. UVA1225 ​​​​​​​Digit Counting
  7. 想跑次高频策略?快来看看Numpy处理真格量化tick数据的技巧
  8. ng-notadd 0.10.1,基于 Angular7 和 material2 的中后台解决方案
  9. 转:VMware安装Mac OS X Mavericks系统图文教程
  10. WCF Data Services 基础