in reply to Displaying bit-vectors with Most Significant Bits to the left?
Creating the vector in one 16-bit operation rather than several 1-bit operations simplifies the unpack process.
johngg@shiraz:~/perl/Monks$ perl -Mstrict -Mwarnings -E ' my @bitPosns = ( 0, 2, 8, 9, 10 ); my $val; $val += 2 ** $_ for @bitPosns; my $vec; vec( $vec, 0, 16 ) = $val; say unpack q{B16}, $vec;' 0000011100000101
Six of one, a half dozen of the other I suppose.
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Displaying bit-vectors with Most Significant Bits to the left?
by ikegami (Patriarch) on Jan 05, 2020 at 14:21 UTC | |
by LanX (Saint) on Jan 05, 2020 at 15:18 UTC | |
by ikegami (Patriarch) on Jan 06, 2020 at 07:09 UTC | |
by LanX (Saint) on Jan 06, 2020 at 14:33 UTC | |
by ikegami (Patriarch) on Jan 07, 2020 at 18:47 UTC |