PHP code example of dshepherd / bitstream-iterator

1. Go to this page and download the library: Download dshepherd/bitstream-iterator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dshepherd / bitstream-iterator example snippets



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