my @rows = ( 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x04, 0x00 ); my @cols = (0) x 8; for my $c ( 0 .. 7 ){ $rows[ $_ ] & 1 << $c and $cols[ $c ] |= 1 << $_ for 0 .. 7; } printf "0x%02x\n", $_ for @cols; 0x00 0x00 0x4f 0x00 0x00 0x00 0x00 0x00