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

Replies are listed 'Best First'.
Re^2: first 5 bits and last 3 bits
by DrHyde (Prior) on Jul 27, 2011 at 09:26 UTC
    If you're creating a bitmask, it's clearer to say 0b11111000 than 0xf8.