Horde_Xml_Wbxml::getBits PHP Method

getBits() public static method

public static getBits ( $num, $l )
    public static function getBits($num, $l)
    {
        switch ($num) {
            case 0:
                return $l & 127;
                // 0x7F
            // 0x7F
            case 1:
                return $l >> 7 & 127;
                // 0x7F
            // 0x7F
            case 2:
                return $l >> 14 & 127;
                // 0x7F
            // 0x7F
            case 3:
                return $l >> 21 & 127;
                // 0x7F
            // 0x7F
            case 4:
                return $l >> 28 & 127;
                // 0x7F
        }
        return 0;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Encoding Multi-byte Integers from Section 5.1
  */
 public static function intToMBUInt32(&$out, $i)
 {
     if ($i > 268435455) {
         $bytes0 = 0 | Horde_Xml_Wbxml::getBits(0, $i);
         $bytes1 = 128 | Horde_Xml_Wbxml::getBits(1, $i);
         $bytes2 = 128 | Horde_Xml_Wbxml::getBits(2, $i);
         $bytes3 = 128 | Horde_Xml_Wbxml::getBits(3, $i);
         $bytes4 = 128 | Horde_Xml_Wbxml::getBits(4, $i);
         $out .= chr($bytes4) . chr($bytes3) . chr($bytes2) . chr($bytes1) . chr($bytes0);
     } elseif ($i > 2097151) {
         $bytes0 = 0 | Horde_Xml_Wbxml::getBits(0, $i);
         $bytes1 = 128 | Horde_Xml_Wbxml::getBits(1, $i);
         $bytes2 = 128 | Horde_Xml_Wbxml::getBits(2, $i);
         $bytes3 = 128 | Horde_Xml_Wbxml::getBits(3, $i);
         $out .= chr($bytes3) . chr($bytes2) . chr($bytes1) . chr($bytes0);
     } elseif ($i > 16383) {
         $bytes0 = 0 | Horde_Xml_Wbxml::getBits(0, $i);
         $bytes1 = 128 | Horde_Xml_Wbxml::getBits(1, $i);
         $bytes2 = 128 | Horde_Xml_Wbxml::getBits(2, $i);
         $out .= chr($bytes2) . chr($bytes1) . chr($bytes0);
     } elseif ($i > 127) {
         $bytes0 = 0 | Horde_Xml_Wbxml::getBits(0, $i);
         $bytes1 = 128 | Horde_Xml_Wbxml::getBits(1, $i);
         $out .= chr($bytes1) . chr($bytes0);
     } else {
         $bytes0 = 0 | Horde_Xml_Wbxml::getBits(0, $i);
         $out .= chr($bytes0);
     }
 }