in reply to Optimize bit stream conversion
Update: handle complete bytes (new secret operator %8||-).#!/usr/bin/perl use warnings; use strict; my @bits = ( 1, 0, 0, 0, 0, 0, 1, 0, # A / 0x41 / 0b01000001 0, 1, 0, 0, 0, 0, 1, 0, # B / 0x42 / 0b01000010 1, 1, 0, 0, 1, 0, 1 # incomplete byte ); my $string = join q(), @bits; my $incomplete = @bits % 8 || -@bits; # The || part handle +s complete bytes. print pack "b*", substr $string, 0, -$incomplete; splice @bits, 0, -$incomplete; # Remove the process +ed part. print "\n@bits\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Optimize bit stream conversion
by Monk::Thomas (Friar) on Jul 30, 2015 at 12:19 UTC | |
by choroba (Cardinal) on Jul 30, 2015 at 13:01 UTC |