in reply to first 5 bits and last 3 bits
Use bitmask and bitwise boolean operations.
fisher% perl -e 'my $byte=129; my $first5=$byte&0xf8; printf "%08b, %d +\n", $byte, $first5;' 10000001, 128
In Section
Seekers of Perl Wisdom