<?php
GMP gmp_com ( GMP|int|string $num )
where,
$num = GMP number to obtain the complement
?>
<?php
$a01 = [ '04553207',
04553207,
// octal
'0x12D687',
0x12D687,
//hexadecimal
'1234567',
1234567
// decimal
];
foreach($a01 as $v01)
{
$c01 = gmp_com($v01);
echo 'gmp_com( ' . $v01 . ' ) = ' . gmp_strval($c01) . '<br><br>';
}
?>
<?php
var_dump(gmp_strval(gmp_com(0)));
echo '<br><br>';
var_dump(gmp_strval(gmp_com("0")));
echo '<br><br>';
/*
try {
var_dump(gmp_strval(gmp_com("test")));
} catch (\TypeError $e) {
echo $e->getMessage() . "<br><br>";
}
*/
var_dump(gmp_strval(gmp_com(017)));
echo '<br><br>';
var_dump(gmp_strval(gmp_com("017")));
echo '<br><br>';
var_dump(gmp_strval(gmp_com(0x1A)));
echo '<br><br>';
var_dump(gmp_strval(gmp_com("0x1A")));
echo '<br><br>';
var_dump(gmp_strval(gmp_com("2394876545678")));
echo '<br><br>';
var_dump(gmp_strval(gmp_com("-111")));
echo '<br><br>';
var_dump(gmp_strval(gmp_com(874653)));
echo '<br><br>';
var_dump(gmp_strval(gmp_com(-9876)));
echo '<br><br>';
$n = gmp_init("98765467");
var_dump(gmp_strval(gmp_com($n)));
echo '<br><br>';
$n = gmp_init("98765463337");
var_dump(gmp_strval(gmp_com($n)));
echo '<br><br>';
/*
try {
var_dump(gmp_strval(gmp_com(array())));
echo '<br><br>';
} catch (\TypeError $e) {
echo $e->getMessage() . "<br><br>";
}
*/
?>
<?php
$a03 = [ -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 12 ];
$base03 =10;
$base03a = $base03 -9;
foreach($a03 as $k03 => $v03)
{
$c03 = gmp_com($v03);
echo 'gmp_com( ' . $v03 . ' ) = ' . $c03 . '<br> The same as ';
echo $base03 - $a03[$k03] - $base03 -1 . '<br><br>';
}
?>
<?php
$a04 = [ '0000', '0001', '0010', '0011', '1100', '1101', '1110', '1111' ];
foreach($a04 as $k04 => $v04)
{
$b04 = bindec($v04);
$c04 = gmp_com($b04);
echo 'gmp_com( ' . $b04 . ' ) = ' . $c04 . '<br>';
}
?>
<?php
$bin05arr = ['01111111', '01111110',
'00000010', '00000001',
'00000000', '11111111',
'11111110', '11111101',
'10000001', '10000000'];
foreach($bin05arr as $bin05)
{
$dec05 = bindec($bin05);
$str05 = gmp_com($dec05);
echo $dec05 . ' = ' . $bin05 . '<br>Complement ' . $str05 . '<br><br>';
}
?>