public PatternBlock andBlock(PatternBlock b) {
		PatternBlock res = new PatternBlock(true);
		int maxlength = (getLength() > b.getLength()) ? getLength() : b.getLength();

		int asize = maxlength / 4;
		if (maxlength % 4 != 0) {
			asize += 1;
		}
		res.maskvec = new int[asize];
		res.valvec = new int[asize];
		res.offset = 0;
		int offset1 = 0;
		int i = 0;
		int mask1, val1, mask2, val2;
		while (offset1 < maxlength) {
			mask1 = getMask(offset1 * 8, 32);
			val1 = getValue(offset1 * 8, 32);
			mask2 = b.getMask(offset1 * 8, 32);
			val2 = b.getValue(offset1 * 8, 32);
			if (((mask2 & mask1) & val2) != ((mask2 & mask1) & val1)) {
				break;	// Impossible pattern
			}
			res.maskvec[i] = mask1 | mask2;
			res.valvec[i] = val1 | val2;
			offset1 += 4;
			i += 1;
		}
		if (offset1 < maxlength) { // If pattern is impossible
			res.nonzerosize = -1;
		}
		else { // If pattern is impossible
			res.nonzerosize = maxlength;
		}
		res.normalize();
		return res;
	}
A mask/value pair viewed as two bitstreams
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/pattern/PatternBlock.java