testbitshift.php - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of testbitshift.php.php
- <?php
- $val = 4;
- $places = 3;
- $res = $val << $places;
- p($res, $val, '<<', $places, 'sign bits get shifted out');
- function p($res, $val, $op, $places, $note = '') {
- $format = '%0' . (PHP_INT_SIZE * 8) . "b\n";
- printf("Expression: %d = %d %s %d\n", $res, $val, $op, $places);
- echo " Decimal:\n";
- printf(" val=%d\n", $val);
- printf(" res=%d\n", $res);
- echo " Binary:\n";
- printf(' val=' . $format, $val);
- printf(' res=' . $format, $res);
- if ($note) {
- echo " NOTE: $note\n";
- }
- echo "\n";
- }
- ?>
File Description
- testbitshift.php
- PHP Code
- 06 Feb-2020
- 549 Bytes
You can Share it:
Latest PHP Pastes