gmp_strvalCONVERT a GMP number to a STRING.
The GMP can be either a RESOURCE, an OBJECT or a NUMERIC STRING provided that it is possible to convert the latter to a number.
The default $base = 10 others may be instituted by $base ∈ [ -2, -36 ] or $base ∈ [ 2, 62 ].
<?php
string gmp_strval ( GMP|int|string $num, int $base = 10 )
where,
$num = The GMP number to be converted to STRING
$base = The base to consider
?>
$num
The GMP number to be converted to STRING.
$base
The base to be considered.
EXERCISE
<?php
// $val01 = mt_rand(1, 161600);
$val01 = 161600;
// DECIMAL VALUE
$gmp01 = [ -2, -36, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 62 ];
// DECIMAL BASES
foreach($gmp01 as $gm01)
{
echo '( ' . $val01 . ' )<sub>10</sub> = ( ' . gmp_strval($val01, $gm01) . ' )<sub>' . $gm01 . '</sub><br>';
}
?>
RESULT
( 161600 )10 = ( 100111011101000000 )-2
( 161600 )10 = ( 3GOW )-36
( 161600 )10 = ( 100111011101000000 )2
( 161600 )10 = ( 22012200012 )3
( 161600 )10 = ( 213131000 )4
( 161600 )10 = ( 20132400 )5
( 161600 )10 = ( 3244052 )6
( 161600 )10 = ( 1242065 )7
( 161600 )10 = ( 473500 )8
( 161600 )10 = ( 265605 )9
( 161600 )10 = ( 161600 )10
( 161600 )10 = ( 10045a )11
( 161600 )10 = ( 79628 )12
( 161600 )10 = ( 5872a )13
( 161600 )10 = ( 42c6c )14
( 161600 )10 = ( 32d35 )15
( 161600 )10 = ( 27740 )16
( 161600 )10 = ( 1ff2f )17
( 161600 )10 = ( 19cde )18
( 161600 )10 = ( 14ac5 )19
( 161600 )10 = ( 10400 )20
( 161600 )10 = ( h995 )21
( 161600 )10 = ( f3ja )22
( 161600 )10 = ( d6b2 )23
( 161600 )10 = ( bgd8 )24
( 161600 )10 = ( a8e0 )25
( 161600 )10 = ( 951a )26
( 161600 )10 = ( 85i5 )27
( 161600 )10 = ( 7a3c )28
( 161600 )10 = ( 6i4c )29
( 161600 )10 = ( 5tgk )30
( 161600 )10 = ( 5d4s )31
( 161600 )10 = ( 4tq0 )32
( 161600 )10 = ( 4gcw )33
( 161600 )10 = ( 43qw )34
( 161600 )10 = ( 3qw5 )35
( 161600 )10 = ( 3gow )36
( 161600 )10 = ( 371L )37
( 161600 )10 = ( g2S )62
EXERCISE
<?php
// $val02 = mt_rand(01, 0473500);
$val02 = 0473500;
// OCTAL VALUE OF 161600
$gmp02 = [ -2, -36, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 62 ];
// DECIMAL BASES
foreach($gmp02 as $gm02)
{
echo '( ' . $val02 . ' )<sub>10</sub> = ( ' . gmp_strval($val02, $gm02) . ' )<sub>' . $gm02 . '</sub><br>';
}
?>
EXERCISE
<?php
// $val03 = mt_rand(0x1, 0x27740);
$val03 = 0x27740;
// HEX VALUE OF 161600
$gmp03 = [ -2, -36, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 62 ];
// DECIMAL BASES
foreach($gmp03 as $gm03)
{
echo '( ' . $val03 . ' )<sub>10</sub> = ( ' . gmp_strval($val03, $gm03) . ' )<sub>' . $gm03 . '</sub><br>';
}
?>
EXERCISE
<?php
$val04 = 0x27740;
// HEX VALUE OF 161600
$gmp04 = [ 02, 03, 04, 05, 06, 07, 010,
011, 012, 013, 014, 015, 016,
017, 042, 043, 044, 045, 075, 076 ];
// OCTAL BASES
foreach($gmp04 as $gm04)
{
echo '( ' . $val04 . ' )<sub>10</sub> = ( ' . gmp_strval($val04, $gm04) . ' )<sub>' . $gm04 . '</sub><br>';
}
?>
EXERCISE
<?php
$val05 = 0473500;
// OCTAL VALUE OF 161600
$gmp05 = [ 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x10,
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x23,
0x25, 0x35, 0x36, 0x3c, 0x3d, 0x3e ];
// HEX BASES
foreach($gmp05 as $gm05)
{
echo '( ' . $val05 . ' )<sub>10</sub> = ( ' . gmp_strval($val05, $gm05) . ' )<sub>' . $gm05 . '</sub><br>';
}
?>