function extract_bits($number, $N, $pos) {
return (((1 << $N) - 1) & ($number >> ($pos - 1)));
}
$number = 441;
$N = 6;
$pos = 5;
/*
str_replace(
array|string $search,
array|string $replace,
string|array $subject,
int &$count = null
): string|array
*/
echo str_replace(" ", "0", sprintf("%16s", decbin($number))) . "\n";
$extracted_bits = extract_bits($number, $N, $pos);
echo str_replace(" ", "0", sprintf("%16s", decbin($extracted_bits)));
/*
run:
0000000110111001
0000000000011011
*/