I've never dealt with bits and bytes, so I'm unable to figure out the first 5 bits and last 3 bits of say 129... supposed to get 16 and 3 or 2 or something... Thank you!
I sort of came up with this, but it's not nice:
#!/usr/bin/perl
#
$num = 129;
$str = unpack("B32", pack("N", $num));
$str =~ s/^0+(?=\d)//; # otherwise you'll get leading zeros
print "$str\n";
$fragment = substr $str, 0, 5; #first 5 bytes
print "$fragment\n";
$num1=unpack("N", pack("B32", substr("0" x 32 . $fragment, -32)));
print "num1=$num1\n";
$fragment = substr $str, 5, 3; #first 5 bytes
print "$fragment\n";
$num2=unpack("N", pack("B32", substr("0" x 32 . $fragment, -32)));
print "num2=$num2\n";