- substr: documentation ( source)
- var_dump: documentation ( source)
- intval: documentation ( source)
<?php
/* convert 64-bit numeric string to decimal
*/
function showDecimal( $bin, $base ) {
if ($bin[0] == 'F' && $bin[1] == 'F'){
$bin = substr($bin,1); // trim string so may
}
$num = intval( $bin, $base ); // convert to binary number
$num &= 0xffff; // using only rightmost 16 bits
if ( 0x8000 & $num ) { // true if $num is negative ...
$num =( $num - (2 ** 16) );
$num2 = -((2 ** 16) - 0xfffd);
var_dump($num2);
}
return $num;
}
$c = "FFFFFFFFFFFFFFFD"; // TC in hexadecimal for:
echo showDecimal($c,16),"\n"; // -3