Skip to content

Latest commit

 

History

History
30 lines (20 loc) · 624 Bytes

README.md

File metadata and controls

30 lines (20 loc) · 624 Bytes

Bitstream Iterator


Installation

composer require dshepherd/bitstream-iterator

Usage

$bytes = [0xDE, 0xCA, 0xFB, 0xAD, 0xD0];

$iterator = new BitStreamIterator($bytes);

$message = dechex(bindec(implode('', $iterator->take(20))));
$message .= ' ' . dechex(bindec(implode('', $iterator->take(12))));
$flag = $iterator->take(1);
$options = $iterator->take(3);

printf('Message: %s' . PHP_EOL, $message);
printf('Flag is %s' . PHP_EOL, $flag ? 'set' : 'not set');

for ($x = 0; $x < 4; $x++) {
    printf('Bit %d is %s' . PHP_EOL, $x, ($options & pow($x, 2)) != 0 ? 'set' : 'not set');
}