My self-study in php.net and here has so far not enabled me to find any approach! My experiments with operators like &
and >>
or <<
I do not want to show here - too embarrassing!
The starting point are arrays of different lengths with integer values (always 8-bit).
So for instance:
[178, 89, 1]
Their binary coded equivalent...
10110010, 01011001, 00000001
should be, least significant bit first,...
01001101, 10011010, 10000000
concatenated:
010011011001101010000000
Can someone explain the procedure to me step by step, so that I understand the bit operations in php?
Thank you
Post scriptum: I don't want to solve the problem with string operations (I can do that - but it's terribly slow!), but with bit operations.
probably you need something like this:
<?php
$array = [178, 89, 1];
$output = 0;
foreach ($array as $v) {
for ($i = 0; $i < 8; $i++) {
$output = ($output << 1) | ($v & 1);
$v = $v >> 1;
}
}
echo $output . " " . str_pad(decbin($output), 24, 0, STR_PAD_LEFT);
now step by step:
$v & 1
$output << 1
|
part