mossi2000 has asked for the wisdom of the Perl Monks concerning the following question:
my $bytes_per_value = 5; # to simulate the byte stream using 40bit = 5 * 8bit; my $value = 0xf_dead_beef_4; my $bin_value = substr (pack ('Q', $value), 0, $bytes_per_value); my $buffer = $bin_value x 4 my $nbytes = length ($buffer); my $fmt = sprintf "(b%d)*", $bytes_per_value << 3; my @stream_data = unpack ($fmt, substr ($buffer, 0, $nbytes)); my @values = map { oct '0b'.reverse ($_)} @stream_data; foreach my $v (@values) { printf "0x%x\n", $v; }
My question:
Is there a way to unpack this stream directly into an array of QWords (64bit)
using some form of unpack for 5,6 and 7 byte data. (The 8 byte case is obviously easy :-) )
Means: Can I specify via the format string to convert 5,6 or 7 bytes + 3,2 or 1 padding Zero bytes
to a 64bit integer?
Or can unpack only work on "existing" data bytes.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Can unpack add zero bytes before converting?
by vr (Curate) on Sep 13, 2021 at 11:19 UTC | |
by vr (Curate) on Sep 13, 2021 at 20:40 UTC | |
|
Re: Can unpack add zero bytes before converting?
by Anonymous Monk on Sep 12, 2021 at 16:45 UTC | |
by tybalt89 (Monsignor) on Sep 12, 2021 at 19:00 UTC | |
by Anonymous Monk on Sep 13, 2021 at 12:45 UTC | |
|
Re: Can unpack add zero bytes before converting?
by AnomalousMonk (Archbishop) on Sep 13, 2021 at 02:10 UTC | |
|
Re: Can unpack add zero bytes before converting?
by mossi2000 (Initiate) on Sep 13, 2021 at 13:19 UTC |