protected static function toBitArray($string) { $result = new BitArray(); for ($i = 0; $i < strlen($string); $i++) { if ($string[$i] == 'X') { $result->append(1); } elseif ($string[$i] == '.') { $result->append(0); } } return $result; }
public function encode($data) { $result = new BitArray(); while (strlen($data) >= 32) { $chunkLength = min(strlen($data), 2048 + 32 - 1); $result->append(self::CODE_UPPER_BS, 5); $result->append(0, 5); $result->append($chunkLength - 32, 11); $result->appendBytes(substr($data, 0, $chunkLength)); $data = substr($data, $chunkLength); } if (strlen($data) > 0) { $result->append(self::CODE_UPPER_BS, 5); $result->append(strlen($data), 5); $result->appendBytes($data); } return $result; }
public function appendTo(BitArray $bitArray, array $text) { for ($i = 0; $i < $this->shiftByteCount; $i++) { if ($i == 0 || $i == 31 && $this->shiftByteCount <= 62) { $bitArray->append(31, 5); if ($this->shiftByteCount > 62) { $bitArray->append($this->shiftByteCount - 31, 16); } elseif ($i == 0) { $bitArray->append(min($this->shiftByteCount, 31), 5); } else { $bitArray->append($this->shiftByteCount - 31, 5); } } $bitArray->append(ord($text[$this->shiftStart + $i]), 8); } return $bitArray; }
private static function drawModeMessage(BitMatrix $matrix, $compact, $matrixSize, BitArray $modeMessage) { $center = intval($matrixSize / 2); if ($compact) { for ($i = 0; $i < 7; $i++) { if ($modeMessage->get($i)) { $matrix->set($center - 3 + $i, $center - 5); } if ($modeMessage->get($i + 7)) { $matrix->set($center + 5, $center - 3 + $i); } if ($modeMessage->get(20 - $i)) { $matrix->set($center - 3 + $i, $center + 5); } if ($modeMessage->get(27 - $i)) { $matrix->set($center - 5, $center - 3 + $i); } } } else { for ($i = 0; $i < 10; $i++) { if ($modeMessage->get($i)) { $matrix->set($center - 5 + $i + intval($i / 5), $center - 7); } if ($modeMessage->get($i + 10)) { $matrix->set($center + 7, $center - 5 + $i + intval($i / 5)); } if ($modeMessage->get(29 - $i)) { $matrix->set($center - 5 + $i + intval($i / 5), $center + 7); } if ($modeMessage->get(39 - $i)) { $matrix->set($center - 7, $center - 5 + $i + intval($i / 5)); } } } return $matrix; }
public function testAppendBytes() { $array = new BitArray(2); $array->appendBytes('AB'); $this->assertEquals(array(0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0), $array->asArray()); }
public function appendTo(BitArray $bitArray, array $text) { $bitArray->append($this->value, $this->bitCount); return $bitArray; }