Java BigInteger andNot操作

2023-08-03  本文已影响0人  kaiker

Java BigInteger的andNot 逻辑
A.andNot(B) 是先对B取非再做与。

010 andNot 100 
010 and (not 100)
010 and 011
= 010

主要的应用场景,A是否是B的子集就可以用andNot判断,如果都是0说明A出现的位在B中都出现过。

import java.math.BigInteger;

public class BitCal {

    public static void main(String[] args) {
        BigInteger A = BigInteger.valueOf(2);
        BigInteger B = BigInteger.valueOf(4);
        System.out.println(A.andNot(B));
    }

}
上一篇 下一篇

猜你喜欢

热点阅读