- var_dump: documentation ( source)
- decbin: documentation ( source)
- strrev: documentation ( source)
- str_split: documentation ( source)
<?php
$bitMask = 5;
$bitMask = str_split(strrev((string)decbin((int)$bitMask)));
$splited = array();
foreach($bitMask as $pos => $bit) {
if (0 != $bit) {
$splited[] = /* pow(2, $pos); */ (1 << $pos);
}
}
var_dump($splited);