Java BigInteger类| bitCount()方法与示例
BigInteger类的bitCount()方法 (BigInteger Class bitCount() method)
bitCount() method is available in java.math package.
bitCount()方法在java.math包中可用。
bitCount() method is used to count the number of bits in 2’s complement denotation of this BigInteger.
bitCount()方法用于计算此BigInteger的2的补码表示形式中的位数。
bitCount() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
bitCount()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
bitCount() method does not throw an exception at the time of counting bits.
在对位进行计数时, bitCount()方法不会引发异常。
Syntax:
句法:
public int bitCount();
Parameter(s):
参数:
None
没有
Return value:
返回值:
The return type of this method is BigInteger, it returns number of bits in 2's complement denotation of this BigInteger.
此方法的返回类型为BigInteger ,它返回此BigInteger的2的补码表示形式的位数。
Example:
例:
// Java program to demonstrate the example
// of int bitCount() method of BigInteger
import java.math.*;
public class BitCountOfBI {public static void main(String args[]) {// Initialize two variables str1 and str2
String str1 = "10";
String str2 = "-4";
// Initialize two BigInteger objects
BigInteger b_int1 = new BigInteger(str1);
BigInteger b_int2 = new BigInteger(str2);
System.out.println("b_int1: " + b_int1);
System.out.println("b_int2: " + b_int2);
// returns the number of bits in 2's complement
// representation of this BigInteger b_dec1
int bit_count = b_int1.bitCount();
System.out.println("b_int1.bitCount(): " + bit_count);
// returns the number of bits in 2's complement
// representation of this BigInteger b_dec2 and it
// may differ from its sign bit
bit_count = b_int2.bitCount();
System.out.println("b_int2.bitCount(): " + bit_count);
}
}
Output
输出量
b_int1: 10
b_int2: -4
b_int1.bitCount(): 2
b_int2.bitCount(): 2
翻译自: https://www.includehelp.com/java/biginteger-bitcount-method-with-example.aspx
Java BigInteger类| bitCount()方法与示例相关推荐
- java annotation class,Java Class类 isAnnotation()方法及示例
Class类isAnnotation()方法isAnnotation()方法在java.lang包中可用. isAnnotation()方法用于检查此Class对象是否表示注释类型. isAnnota ...
- java字符类型的返回值,Java字符类isWhitespace()方法及示例
Character 类isWhitespace()法isWhitespace()方法在java.lang包中可用. isWhitespace()方法用于检查给定的char值是否为空格,但是它包含空格中 ...
- Java BigInteger类| 带示例的shiftLeft()方法
BigInteger类shiftLeft()方法 (BigInteger Class shiftLeft() method) shiftLeft() method is available in ja ...
- Java BigInteger类| modInverse()方法与示例
BigInteger类modInverse()方法 (BigInteger Class modInverse() method) modInverse() method is available in ...
- Java BigInteger类| and()方法与示例
BigInteger类和()方法 (BigInteger Class and() method) and() method is available in java.math package. and ...
- Java BigInteger类| 带有示例的减去()方法
BigInteger类减去()方法 (BigInteger Class subtract() method) subtract() method is available in java.math p ...
- Java BigInteger类| toByteArray()方法与示例
BigInteger类testBit()方法 (BigInteger Class testBit() method) testBit() method is available in java.mat ...
- Java BigInteger类| nextProbablePrime()方法与示例
BigInteger类nextProbablePrime()方法 (BigInteger Class nextProbablePrime() method) nextProbablePrime() m ...
- Java BigInteger类| hashCode()方法与示例
BigInteger类hashCode()方法 (BigInteger Class hashCode() method) hashCode() method is available in java. ...
最新文章
- [蓝桥杯2018初赛]全球变暖-dfs,bfs,连通块
- 高品质平板电脑模型为您的作品演示加分
- 题目1022:游船出租(结构体使用)
- Android开发笔记(一百六十三)高仿京东的沉浸式状态栏
- SpeedTree学习笔记(转)
- “迷失自我”,请记住下面5个网站,让你受益终身
- CV+Deep Learning——网络架构Pytorch复现系列——classification(一:LeNet5,VGG,AlexNet,ResNet)
- 信息安全管理体系(ISMS)
- vue 关于飞行地图展示的功能
- ps裁剪和裁切的区别_PS裁剪和裁切的区别
- html5判断屏幕锁屏,js实现自动锁屏功能
- i5 13500怎么样相当于什么水平级别
- 仿微信清理内存图表动画(解决surfaceView闪烁问题)
- SQL取日期为当前月份的第几周思路
- 【Beta】Scrum Meeting 4
- 第二天-01-虚拟机快照和克隆
- 统计学之基础知识(数据分析准备)
- 【网络设备】交换机相同VLAN之间互通
- shells - 有效登录 shell 的路径名
- 『每周译Go』GitHub 为 Go 社区带来供应链安全功能
热门文章
- mysql异步查询 java_基于 mysql 异步驱动的非阻塞 Mybatis
- python井字棋ai_实现AI下井字棋的alpha-beta剪枝算法(python实现)
- python gui入门的例子_Python GUI编程之Tkinter入门之道
- 在c语言程序中 对文件进行操作首先要,《C语言程序设计》试题八及答案
- elasticsearch存储空间不足导致索引只读,不能创建
- Shell编程—企业生产案例
- JMS(Java消息服务)与消息队列ActiveMQ基本使用(一)
- 在eclipse中启动Tomcat访问localhost:8080失败项目添加进Tomcat在webapp中找不到
- WAS集群系列(5):集群搭建:步骤3:安装IHS软件
- jQuery 倒计时