Java程序在BigInteger中翻转
要在Java中的BigInteger中翻转一点,请使用flipBit()方法。此方法返回一个BigInteger,其值等于指定位被翻转的BigInteger。
示例
import java.math.*;
public class Demo {
public static void main(String[] args) {
BigInteger one, two;
one = new BigInteger("7");
one = one.flipBit(3);
System.out.println("Result: " +one);
}
}输出结果
Result: 15
让我们来看另一个例子。
示例
import java.math.*;
public class Demo {
public static void main(String[] args) {
BigInteger bi1, bi2;
bi1 = new BigInteger("8");
bi2 = bi1.flipBit(1);
String str = "Flipbit operation on " +bi1+ " at index 1 gives " +bi2;
System.out.println( str );
}
}输出结果
Flipbit operation on 8 at index 1 gives 10
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短