Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Stupid case to process bitmask on PHP
<?php
// source data
$source = array(
false,
true,
true,
false,
true,
true,
false,
false,
true
);
$params = 0b0;
// coder
for($i=0; $i<count($source); $i++) {
$params = $params + ((int)$source[$i] << $i );
}
// decoder
$decoded = array_reverse(str_split(decbin($params),1));
for($i=0;$i<count($decoded);$i++) {
$decoded[$i] = (bool)$decoded[$i];
}
/***************/
echo "<pre>";
var_dump($source);
echo "++++++++++++++++++++".PHP_EOL;
var_dump($params);
echo "++++++++++++++++++++".PHP_EOL;
var_dump($decoded);
echo "</pre>";
/***************/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.