TCPDFBarcode::imb_crc11fcs PHP Method

imb_crc11fcs() protected method

Intelligent Mail Barcode calculation of Frame Check Sequence.
protected imb_crc11fcs ( $code_arr ) : integer
$code_arr (string) array of hexadecimal values (13 bytes holding 102 bits right justified).
return integer 11 bit Frame Check Sequence as integer (decimal base)
    protected function imb_crc11fcs($code_arr)
    {
        $genpoly = 0xf35;
        // generator polynomial
        $fcs = 0x7ff;
        // Frame Check Sequence
        // do most significant byte skipping the 2 most significant bits
        $data = hexdec($code_arr[0]) << 5;
        for ($bit = 2; $bit < 8; ++$bit) {
            if (($fcs ^ $data) & 0x400) {
                $fcs = $fcs << 1 ^ $genpoly;
            } else {
                $fcs = $fcs << 1;
            }
            $fcs &= 0x7ff;
            $data <<= 1;
        }
        // do rest of bytes
        for ($byte = 1; $byte < 13; ++$byte) {
            $data = hexdec($code_arr[$byte]) << 3;
            for ($bit = 0; $bit < 8; ++$bit) {
                if (($fcs ^ $data) & 0x400) {
                    $fcs = $fcs << 1 ^ $genpoly;
                } else {
                    $fcs = $fcs << 1;
                }
                $fcs &= 0x7ff;
                $data <<= 1;
            }
        }
        return $fcs;
    }