TCPDFBarcode::imb_tables PHP Method

imb_tables() protected method

generate Nof13 tables used for Intelligent Mail Barcode.
protected imb_tables ( $n, $size ) : array
$n (int) is the type of table: 2 for 2of13 table, 5 for 5of13table
$size (int) size of table (78 for n=2 and 1287 for n=5)
return array requested table
    protected function imb_tables($n, $size)
    {
        $table = array();
        $lli = 0;
        // LUT lower index
        $lui = $size - 1;
        // LUT upper index
        for ($count = 0; $count < 8192; ++$count) {
            $bit_count = 0;
            for ($bit_index = 0; $bit_index < 13; ++$bit_index) {
                $bit_count += intval(($count & 1 << $bit_index) != 0);
            }
            // if we don't have the right number of bits on, go on to the next value
            if ($bit_count == $n) {
                $reverse = $this->imb_reverse_us($count) >> 3;
                // if the reverse is less than count, we have already visited this pair before
                if ($reverse >= $count) {
                    // If count is symmetric, place it at the first free slot from the end of the list.
                    // Otherwise, place it at the first free slot from the beginning of the list AND place $reverse ath the next free slot from the beginning of the list
                    if ($reverse == $count) {
                        $table[$lui] = $count;
                        --$lui;
                    } else {
                        $table[$lli] = $count;
                        ++$lli;
                        $table[$lli] = $reverse;
                        ++$lli;
                    }
                }
            }
        }
        return $table;
    }