Skip to content

dan-abc/bitstream-iterator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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');
}

About

A class for iterating through a stream of bits

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages