Beispiel #1
0
 /**
  * Tests the conversion of a hexadecimal string into a signed integer.
  *
  * @dataProvider hexToSignedIntProvider
  * @covers hexToSignedInt
  *
  * @param string $hex a hexadecimal string
  * @param int $res the resulting signed integer
  */
 public function testHexToSignedInt($hex, $res)
 {
     $this->assertSame($res, Math::hexToSignedInt($hex));
 }
Beispiel #2
0
 /**
  * Decodes a GID string and outputs the results as array.
  *
  * @param string $gid the GID to parse
  * @return array boolean array with indices <code>type</code>, <code>crc32Name</code>,
  * <code>localID</code> and <code>uniqueID</code> for the GID type, CRC32 of name (hexadecimal),
  * local ID and unique ID or <code>false</code> if the GID string is malformed
  */
 public function decode($gid)
 {
     if (!preg_match('#^[0-9a-f]{32}$#', $gid)) {
         return false;
     }
     $res = array();
     $res['type'] = (int) hexdec($gid[0]);
     $res['crc32Name'] = ltrim(substr($gid, 1, 8), '0');
     if (empty($res['crc32Name'])) {
         $res['crc32Name'] = '0';
     }
     $res['localID'] = Math::hexToSignedInt(ltrim(substr($gid, 9, 8), '0'));
     $res['uniqueID'] = ltrim(substr($gid, 17, 13), '0');
     return $res;
 }