java biginteger之上,Java程序在BigInteger上实现OR操作

本文介绍了Java中BigInteger类的or方法,该方法用于对两个BigInteger对象执行按位或操作。示例代码展示了如何使用or方法,并通过具体例子说明了当输入为正数时,结果始终为正数。此外,还提供了多个示例来演示不同数值的按位或运算结果。
摘要由CSDN通过智能技术生成

TheBigInteger.or(BigInteger val)返回一个BigInteger,其值为(this | val)。当且仅当this或val为负数时,此方法才返回负数BigInteger。

此处,“ val”是与此BigInteger进行“或”运算的值。

以下是一个例子-

示例import java.math.*;

public class Demo {

public static void main(String[] args) {

BigInteger one, two, three;

one = new BigInteger("6");

two = one.or(one);

System.out.println("Result (or operation): " +two);

}

}

输出结果Result (or operation): 6

让我们看另一个例子-

示例import java.math.*;

public class Demo {

public static void main(String[] args) {

BigInteger bi1, bi2, bi3;

bi1 = new BigInteger("9");

bi2 = new BigInteger("16");

bi3 = bi1.or(bi2);

String str = "OR operation on " + bi1 +" and " + bi2 + " gives " +bi3;

System.out.println( str );

}

}

输出结果OR operation on 9 and 16 gives 25

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值