#!/usr/bin/perl -w

use strict;

my @block_a = (
	[1, 1, 0, 0],
	[1, 0, 1, 1],
	[1, 0, 1, 0],
	[1, 0, 0, 1],
	[0, 0, 0, 0],
	[0, 0, 0, 1],
	[0, 0, 1, 0],
	[0, 0, 1, 1]);

my @block_b = (
	[0, 1, 0, 0],
	[0, 1, 0, 1],
	[0, 1, 1, 0],
	[0, 1, 1, 1],
	[0, 1, 1, 1],
	[0, 1, 1, 1],
	[0, 1, 1, 0],
	[0, 1, 0, 1]);

my @block_c = (
	[0, 1, 0, 0],
	[0, 1, 0, 1],
	[0, 0, 1, 0],
	[0, 0, 0, 1],
	[0, 0, 0, 0],
	[1, 0, 0, 1],
	[1, 0, 1, 0],
	[1, 0, 1, 1]);

my @block_d = (
	[1, 1, 0, 0],
	[1, 1, 0, 1],
	[1, 1, 1, 0],
	[1, 1, 1, 1],
	[1, 1, 1, 1],
	[1, 1, 1, 1],
	[1, 1, 1, 0],
	[1, 1, 0, 1]);

$" = '';
my $i = 0;
print "Array A\nBinary\tDecimal\tHex\n";
while (my @row = @{$block_a[$i++]}) {
	my $str =  join('', $row[0], $row[3], $row[2], $row[1]);
	print $str;
	my $val = 0;
	if ($row[0] == '1') {
		$val += 8;
	}
	if ($row[1] == '1') {
		$val += 1;
	}
	if ($row[2] == '1') {
		$val += 2;
	}
	if ($row[3] == '1') {
		$val += 4;
	}
	printf("\t%d", $val);
	printf("\t%x\n", $val);
}

print "Array B\nBinary\tDecimal\tHex\n";
while (my @row = @{$block_b[$i++]}) {
	my $str =  join('', $row[0], $row[3], $row[2], $row[1]);
	print $str;
	my $val = 0;
	if ($row[0] == '1') {
		$val += 8;
	}
	if ($row[1] == '1') {
		$val += 1;
	}
	if ($row[2] == '1') {
		$val += 2;
	}
	if ($row[3] == '1') {
		$val += 4;
	}
	printf("\t%d", $val);
	printf("\t%x\n", $val);
}


print "Array C\nBinary\tDecimal\tHex\n";
while (my @row = @{$block_c[$i++]}) {
	my $str =  join('', $row[0], $row[3], $row[2], $row[1]);
	print $str;
	my $val = 0;
	if ($row[0] == '1') {
		$val += 8;
	}
	if ($row[1] == '1') {
		$val += 1;
	}
	if ($row[2] == '1') {
		$val += 2;
	}
	if ($row[3] == '1') {
		$val += 4;
	}
	printf("\t%d", $val);
	printf("\t%x\n", $val);
}
print "Array D\nBinary\tDecimal\tHex\n";
while (my @row = @{$block_d[$i++]}) {
	my $str =  join('', $row[0], $row[3], $row[2], $row[1]);
	print $str;
	my $val = 0;
	if ($row[0] == '1') {
		$val += 8;
	}
	if ($row[1] == '1') {
		$val += 1;
	}
	if ($row[2] == '1') {
		$val += 2;
	}
	if ($row[3] == '1') {
		$val += 4;
	}
	printf("\t%d", $val);
	printf("\t%x\n", $val);
}

