Exemple #1
0
 public function testAppend()
 {
     $array = new BitArray(2);
     $array->append(0x7, 3);
     $this->assertEquals(5, $array->getLength());
     $this->assertEquals(array(0, 0, 1, 1, 1), $array->asArray());
 }
Exemple #2
0
 public static function generateCheckWords(BitArray $stuffedBits, $totalSymbolBits, $wordSize)
 {
     $messageSizeInWords = intval(($stuffedBits->getLength() + $wordSize - 1) / $wordSize);
     for ($i = $messageSizeInWords * $wordSize - $stuffedBits->getLength(); $i > 0; $i--) {
         $stuffedBits->append(1);
     }
     $totalSizeInFullWords = intval($totalSymbolBits / $wordSize);
     $messageWords = self::bitsToWords($stuffedBits, $wordSize, $totalSizeInFullWords);
     $rs = new ReedSolomonEncoder(self::getGF($wordSize));
     $messageWords = $rs->encodePadded($messageWords, $totalSizeInFullWords - $messageSizeInWords);
     $startPad = $totalSymbolBits % $wordSize;
     $messageBits = new BitArray();
     $messageBits->append(0, $startPad);
     foreach ($messageWords as $messageWord) {
         $messageBits->append($messageWord, $wordSize);
     }
     return $messageBits;
 }