src/main/java/com/osiris/maths/binary/Bits.java
/**
     * Performs a logical AND operation for each individual bit.
     */
Performs a logical AND operation for each individual bit.
Performs a logical AND operation for each individual bit .
public Bits and(Bits num) {
        if (this.bits.size() != num.bits.size()) {
            int missingBits = 0;
            if (bits.size() < num.bits.size()) {
                missingBits = num.bits.size() - bits.size();
                for (int i = 0; i < missingBits; i++) {
                    if(state == State.COMPLEMENT_1 || state == State.COMPLEMENT_2) bits.add(new Bit(true));
                    else bits.add(new Bit(false));
                }
            } else {
                missingBits = bits.size() - num.bits.size();
                for (int i = 0; i < missingBits; i++) {
                    if(state == State.COMPLEMENT_1 || state == State.COMPLEMENT_2) num.bits.add(new Bit(true));
                    else num.bits.add(new Bit(false));
                }
            }
        }
        List<Bit> bits = new ArrayList<>();
        for (int i = 0; i < this.bits.size(); i++) {
            Bit b1 = this.bits.get(i);
            Bit b2 = num.bits.get(i);
            Bit bOutput = new Bit(false);
            new AND(bOutput, b1, b2).fire();
            bits.add(bOutput);
        }
        this.bits = bits;
        return this;
    }
public Bits and ( Bits num ) { if ( this . bits . size ( ) != num . bits . size ( ) ) { int missingBits = 0 ; if ( bits . size ( ) < num . bits . size ( ) ) { missingBits = num . bits . size ( ) - bits . size ( ) ; for ( int i = 0 ; i < missingBits ; i ++ ) { if ( state == State . COMPLEMENT_1 || state == State . COMPLEMENT_2 ) bits . add ( new Bit ( true ) ) ; else bits . add ( new Bit ( false ) ) ; } } else { missingBits = bits . size ( ) - num . bits . size ( ) ; for ( int i = 0 ; i < missingBits ; i ++ ) { if ( state == State . COMPLEMENT_1 || state == State . COMPLEMENT_2 ) num . bits . add ( new Bit ( true ) ) ; else num . bits . add ( new Bit ( false ) ) ; } } } List < Bit > bits = new ArrayList < > ( ) ; for ( int i = 0 ; i < this . bits . size ( ) ; i ++ ) { Bit b1 = this . bits . get ( i ) ; Bit b2 = num . bits . get ( i ) ; Bit bOutput = new Bit ( false ) ; new AND ( bOutput , b1 , b2 ) . fire ( ) ; bits . add ( bOutput ) ; } this . bits = bits ; return this ; }
Performs a logical AND operation for each individual bit.
Performs a logical AND operation for each individual bit .
// Fill missing bits of smaller list