echo decBinary($firstValue, 64) . "\n"; echo '-------------------' . "\n"; echo decBinary($not) . "\n\n\n"; echo 'ZERO NOT (~) [64 bits]:' . "\n"; echo decBinary(0, 64) . "\n"; echo '-------------------' . "\n"; echo decBinary($zeroNot) . "\n\n\n"; echo 'SHIFT LEFT (2^1) (x2):' . "\n"; echo decBinary($firstValue, 16) . "\n"; echo '-----------------------------' . "\n"; echo decBinary($shiftLeft, 16) . "\n\n\n"; echo 'SHIFT TWICE LEFT (2^2) (x4):' . "\n"; echo decBinary($firstValue, 16) . "\n"; echo '-----------------------------' . "\n"; echo decBinary($shiftTwiceLeft, 16) . "\n\n\n"; echo 'SHIFT RIGHT (2^1) (/2):' . "\n"; echo decBinary($firstValue, 16) . "\n"; echo '-----------------------------' . "\n"; echo decBinary($shiftRight, 16) . "\n\n\n"; echo 'SHIFT TWICE RIGHT (2^2) (/4):' . "\n"; echo decBinary($firstValue, 16) . "\n"; echo '-----------------------------' . "\n"; echo decBinary($shiftTwiceRight, 16) . "\n\n\n"; function decBinary($value, $positions = 8) { return sprintf('%5d', $value) . ': ' . binary($value, $positions); } function binary($value, $positions = 8) { return sprintf('%0' . $positions . 'b', $value); }
$decimal = 56; $octal = 0123; //83 $hex = 0xaa; // 170 $binary = 0b10100101; // 165 $float = 567.8; $floatE = 5000.0; // 5 x (10 ^ 3) echo 'Decimal: ' . $decimal . "\n"; echo 'Octal: ' . $octal . "\n"; echo 'Hexadecimal: ' . $hex . "\n"; echo 'Binario: ' . $binary . "\n\n"; echo 'Float: ' . $float . "\n"; echo 'FloatE: ' . $floatE . "\n\n"; $maxInt = PHP_INT_MAX; $negativeMaxInt = -PHP_INT_MAX; $overflow = PHP_INT_MAX + 1; echo 'PHP_INT_MAX [64 bits]: ' . decBinary($maxInt, 64) . ' typeof: ' . gettype($maxInt) . "\n"; echo '-PHP_INT_MAX [64 bits]: ' . decBinary($negativeMaxInt, 64) . ' typeof: ' . gettype($negativeMaxInt) . "\n"; //Nótese que en caso de desbordamiento de entero, PHP no lanza ningún Warning ni peta ni nada, simplemente se convierte a double: echo 'PHP_INT_MAX + 1 (overflow?) [64 bits]: ' . decBinary($overflow, 64) . ' typeof: ' . gettype($overflow) . "\n"; function decBinary($value, $positions = 8) { return sprintf('%5d', $value) . ': ' . binary($value, $positions); } function binary($value, $positions = 8) { return sprintf('%0' . $positions . 'b', $value); }