LdapTools\Utilities\TSProperty::packBitString PHP Метод

packBitString() защищенный Метод

PHP's pack() function has no 'b' or 'B' template. This is a workaround that turns a literal bit-string into a packed byte-string with 8 bits per byte.
protected packBitString ( string $bits, boolean $len ) : string
$bits string
$len boolean
Результат string
    protected function packBitString($bits, $len)
    {
        $bits = substr($bits, 0, $len);
        // Pad input with zeros to next multiple of 4 above $len
        $bits = str_pad($bits, 4 * (int) (($len + 3) / 4), '0');
        // Split input into chunks of 4 bits, convert each to hex and pack them
        $nibbles = str_split($bits, 4);
        foreach ($nibbles as $i => $nibble) {
            $nibbles[$i] = base_convert($nibble, 2, 16);
        }
        return pack('H*', implode('', $nibbles));
    }