<?php
$val = 12;
$bin_val = 1 << ($val -1);
var_dump($bin_val);
var_dump(pow(2, $val - 1));
$val = 1 >> ($val - 1);
var_dump($val);
$binary_string = decbin($bin_val );
// This command test the string with binary values, returning an array with the positions where we have '1'.
$positions = StringHelper::strPosAll(strrev($binary_string), '1');
if (is_array($positions)) {
// We have to add 1 position to fix the "starts with 0 of arrays".
foreach ($positions as $key => $value) {
$positions[$key] = ($value + 1);
}
} else {
$positions = array();
}
var_dump($positions);
int(2048)
int(2048)
int(0)
Fatal error: Uncaught Error: Class "StringHelper" not found in /in/OqBDj:19
Stack trace:
#0 {main}
thrown in /in/OqBDj on line 19
Process exited with code 255.
int(2048)
int(2048)
int(0)
Fatal error: Uncaught Error: Class 'StringHelper' not found in /in/OqBDj:19
Stack trace:
#0 {main}
thrown in /in/OqBDj on line 19
Process exited with code 255.