public int getValue(int startbit, int size) {
		startbit -= 8 * offset;
		int wordnum1 = startbit / 32;
		int shift = startbit % 32;
		int wordnum2 = (startbit + size - 1) / 32;
		int res;

		if ((wordnum1 < 0) || (wordnum1 >= valvec.length)) {
			res = 0;
		}
		else {
			res = valvec[wordnum1];
		}
		res <<= shift;
		if (wordnum1 != wordnum2) {
			int tmp;
			if ((wordnum2 < 0) || (wordnum2 >= valvec.length)) {
				tmp = 0;
			}
			else {
				tmp = valvec[wordnum2];
			}
			res |= (tmp >>> (32 - shift));
		}
		res >>>= 32 - size;
		return res;
	}
A mask/value pair viewed as two bitstreams
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/pattern/PatternBlock.java