#!/home/ben/software/install/bin/perl use warnings; use strict; use PDL; my $g = pdl [ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1], [1, 1, 1, 0], [0, 1, 1, 1], [1, 0, 1, 1], ]; for (0..15) { my @r; # Make the array of bits for my $x (0..3) { $r[3 - $x] = (int ($_ / (1 << $x))) % 2; } my $s = pdl (\@r); # Multiply by $g. my $t = $g x transpose ($s); # Modulo all values by 2. $t = $t % 2; # Get the bits out again. my @bits = $t->list (); # Print. print join ('', @bits), "\n"; }