dshepherd / bitstream-iterator
A class for iterating through a stream of bits
v1.0.0
2018-07-20 19:42 UTC
Requires
- php: ^7.1
This package is not auto-updated.
Last update: 2024-04-14 03:17:51 UTC
README
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'); }