Example usage for java.math BigInteger or

List of usage examples for java.math BigInteger or

Introduction

In this page you can find the example usage for java.math BigInteger or.

Prototype

public BigInteger or(BigInteger val) 

Source Link

Document

Returns a BigInteger whose value is (this | val) .

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    byte[] bytes = new byte[] { 0x1, 0x00, 0x00 };
    BigInteger bi = new BigInteger(bytes);
    bi = bi.or(bi);
}

From source file:Main.java

public static void main(String[] args) {

    // assign values to bi1, bi2
    BigInteger bi1 = new BigInteger("6");
    BigInteger bi2 = new BigInteger("8");

    // perform or operation on bi1, bi2
    BigInteger bi3 = bi1.or(bi2);

    System.out.println(bi3);//from w  ww. ja  v  a 2s .co m
}

From source file:net.ripe.rpki.commons.crypto.util.Asn1Util.java

/**
 * IPAddress ::= BIT STRING// ww  w  .  j  a v a2  s.  co  m
 */
public static IpAddress parseIpAddress(IpResourceType type, ASN1Encodable der, boolean padWithOnes) {
    expect(der, DERBitString.class);
    DERBitString derBitString = (DERBitString) der;

    byte[] bytes = derBitString.getBytes();
    BigInteger value = new BigInteger(1, bytes);
    int usedBits = bytes.length * Byte.SIZE;
    int neededBits = type.getBitSize();
    int padBits = derBitString.getPadBits();

    if (padBits > 0) {
        byte lastByte = bytes[bytes.length - 1];
        byte mask = (byte) ((1 << padBits) - 1);
        Validate.isTrue((lastByte & mask) == 0, "pad bits not zero");
    }

    BigInteger upperBits = value.shiftLeft(neededBits - usedBits);
    BigInteger lowerBits = BigInteger.ZERO;
    if (padWithOnes) {
        lowerBits = BigInteger.ONE.shiftLeft(neededBits - usedBits + padBits).subtract(BigInteger.ONE);
    }

    return (IpAddress) type.fromBigInteger(upperBits.or(lowerBits));
}

From source file:org.opendaylight.genius.interfacemanager.IfmUtil.java

public static BigInteger[] mergeOpenflowMetadataWriteInstructions(List<Instruction> instructions) {
    BigInteger metadata = new BigInteger("0", 16);
    BigInteger metadataMask = new BigInteger("0", 16);
    if (instructions != null && !instructions.isEmpty()) {
        // check if metadata write instruction is present
        for (Instruction instruction : instructions) {
            org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction actualInstruction = instruction
                    .getInstruction();/*from   ww  w.  j  av a  2s  .  co m*/
            if (actualInstruction instanceof WriteMetadataCase) {
                WriteMetadataCase writeMetaDataInstruction = (WriteMetadataCase) actualInstruction;
                WriteMetadata availableMetaData = writeMetaDataInstruction.getWriteMetadata();
                metadata = metadata.or(availableMetaData.getMetadata());
                metadataMask = metadataMask.or(availableMetaData.getMetadataMask());
            }
        }
    }
    return new BigInteger[] { metadata, metadataMask };
}