先决条件: 大整数基础 这个 clearBit() 方法返回用于清除BigInteger中特定位位置的BigInteger。BigInteger二进制表示的索引n处的位将被清除,意味着转换为零。从数学上来说,我们可以说它是用来计算 这是&~(1<
null
public BigInteger clearBit(int n)
参数: 该方法采用一个参数n,该参数表示需要清除的位的索引。 返回值: 该方法在清除位位置n后返回BigInteger。 抛出: 该方法可能会引发 算术异常 当n为负时。 例如:
Input: value = 2300, index = 3Output: 2292Explanation:Binary Representation of 2300 = 100011111100bit at index 3 is 1 so clear the bit at index 3 Now Binary Representation becomes 100011110100and Decimal equivalent of 100011110100 is 2292Input: value = 5482549, index = 0Output: 5482548
下面的程序演示了BigInteger()的clearBit(索引)方法。
JAVA
/* *Program Demonstrate clearBit() method of BigInteger */ import java.math.*; public class GFG { public static void main(String[] args) { // Creating BigInteger object BigInteger biginteger = new BigInteger( "5482549" ); // Creating an int i for index int i = 0 ; // Call clearBit() method on bigInteger at index i // store the return BigInteger BigInteger changedvalue = biginteger.clearBit(i); String result = "After applying clearbit at index " + i + " of " + biginteger+ " New Value is " + changedvalue; // Print result System.out.println(result); } } |
输出:
After applying clearbit at index 0 of 5482549 New Value is 5482548
参考: https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#clearBit(国际)
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END