http://qs321.pair.com?node_id=916754


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