#!/usr/bin/perl

# Idiom #275 Binary digits to byte array

use v5.18;
use strict;

my $s = '1000' . '0010' . '0101' . '1010';   # AZ

my @a;
for ( my $i = 0; $i < length $s; $i += 8) {
    my @b = pack 'b8', substr($s, $i, 8);
    push @a, @b;
}

say '[ "', join('" , "', @a), '" ]';

printf "ordinals of A and Z as binary = %08B%08B\n",ord('A'), ord('Z');
say    'unpack with B* (descending)   = ', unpack 'B*', 'AZ';
