Given a string $old_str, I am trying to extract the first N bits (not bytes) into $new_str. I have been reading the pack documentation and perlpacktut, but am hopelessly confused. This is where I currently stand:
my $old_str = "9876543210";
# Extract the first 5 bits
my $new_str = pack("B5", unpack("B*", $old_str));
printf "%#b | %#b\n", $new_str, $old_str;
This produces:
0b1000 | 0b1001001100101100000001011011101010
But I want this:
0b10010 | 0b1001001100101100000001011011101010
You want the vec built-in: vec
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With