<?php
function string_shift_left($input, $inputlen, $bits, &$output = null)
{
$skip = (int) ($bits / 8);
$copylen = (int) ($inputlen - $skip);
$offset = ($bits % 8) & 0xff;
$mask = ~(0xff >> $offset) & 0xff;
$output = str_pad('', $inputlen + 1, "\x00");
echo "$skip $copylen $offset $mask\n";
if ($offset == 0) {
/* Shifting multiples of 8 allows us to simply copy the relevant bytes */
for ($i = 0; $i < $copylen; $i++) {
$output[$i] = $input[$i + $skip];
}
return;
}
for ($i = 0; $i < $copylen; $i++) {
$left = (ord($input[$i + $skip]) << $offset) & 0xff;
$right = (ord($input[$i + $skip + 1]) & $mask) >> (8 - $offset);
printf("%08b %08b\n", $left, $right);
$output[$i] = chr(($left | $right) & 0xff);
}
}
function string_shift_right($input, $inputlen, $bits, &$output = null)
{
$skip = (int) ($bits / 8);
$copylen = (int) ($inputlen - $skip);
$offsetr = ($bits % 8) & 0xff;
$signbits = (ord($input[0]) & 0x80) == 0 ? 0 : 255;
echo "$skip $copylen $offsetr $signbits\n";
$output = str_pad('', $inputlen + 1, "\x00");
for ($i = 0; $i < $skip; $i++) {
$output[$i] = chr($signbits);
}
if ($offsetr == 0) {
/* Shifting multiples of 8 allows us to simply copy the relevant bytes */
for ($i = $skip, $l = $i + $copylen; $i < $l; $i++) {
$output[$i] = $input[$i - $skip];
}
return;
}
$offsetl = 8 - $offsetr;
$mask = ~(0xff >> $offsetr) & 0xff;
$output[$skip] = chr(($signbits & ~(0xff >> $offsetl)) | (ord($input[0]) >> $offsetr));
for ($i = $skip + 1, $l = $skip + $copylen; $i < $l; $i++) {
$left = ord($input[($i - $skip) - 1]) << $offsetl;
$right = (ord($input[$i - $skip]) & $mask) >> $offsetr;
printf("%08b %08b\n", $left, $right);
$output[$i] = chr($left | $right);
}
}
$input = "abc\x00";
$bits = 5;
string_shift_right($input, strlen($input) - 1, $bits, $output);
for ($i = 0; $i < strlen($input); $i++) {
printf("\n%02x: %08b", ord($input[$i]), ord($input[$i]));
}
for ($i = 0; $i < strlen($output); $i++) {
printf("\n%02x: %08b", ord($output[$i]), ord($output[$i]));
}
- Output for git.master, git.master_jit, rfc.property-hooks
- 0 3 5 0
1100001000 00000011
1100010000 00000011
61: 01100001
62: 01100010
63: 01100011
00: 00000000
03: 00000011
0b: 00001011
13: 00010011
00: 00000000
This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.
Active branches
Archived branches
Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page
preferences:
38.86 ms | 401 KiB | 8 Q