gmp_strval
Description
The gmp_strval of GMP for PHP converts a GMP number to a string.
Syntax
gmp_strval( GMP|int|string $num, int $base = 10 ): string
Parameters
num
The GMP number that will be converted to a string.
A GMP object, an int or a numeric string.
base
The base of the returned number.
The default base is 10. Allowed values for the base are from -2 to -36 and 2 to 62.
Return
The number, as a string.
Examples
1 · num · GMP
<? $num = 1; $num = gmp_init($num); $return = gmp_strval($num); var_dump($return); ?>
string(1) "1"
2 · num · int
<? $num = 1; $return = gmp_strval($num); var_dump($return); ?>
string(1) "1"
3 · num · string
<? $num = "1"; $return = gmp_strval($num); var_dump($return); ?>
string(1) "1"
4 · base · 10
<? $num = 1; $base = 10; $return = gmp_strval($num, $base); var_dump($return); ?>
string(1) "1"
5 · base · -2 to -36
<? $num = 71915494046709; for($i = -2; $i >= -36; --$i) { $base = $i; $return = gmp_strval($num, $base); var_dump($base, $return); } ?>
int(-2) string(47) "10000010110100000100001011110011111101111110101" int(-3) string(30) "100102122001110102121101212210" int(-4) string(24) "100112200201132133233311" int(-5) string(20) "33411230412433443314" int(-6) string(18) "412541304420404033" int(-7) string(17) "21101502661262325" int(-8) string(16) "2026404136375765" int(-9) string(15) "312561412541783" int(-10) string(14) "71915494046709" int(-11) string(14) "20A0720A613495" int(-12) string(13) "8095855546619" int(-13) string(13) "31187A9756B01" int(-14) string(13) "13A8A2AD61285" int(-15) string(12) "84AA48B3C559" int(-16) string(12) "41682179FBF5" int(-17) string(12) "21B75EED0F03" int(-18) string(12) "1229GD73B8D3" int(-19) string(11) "BDG7HCBEH47" int(-20) string(11) "7093JBHFGF9" int(-21) string(11) "46B7J0666CC" int(-22) string(11) "2FCB5I909A5" int(-23) string(11) "1GL7EG118JB" int(-24) string(11) "1357M0D0JCL" int(-25) string(10) "IL7FLEIOI9" int(-26) string(10) "D69LHI5J01" int(-27) string(10) "9BH1CBGANL" int(-28) string(10) "6M9O6F7445" int(-29) string(10) "4RM1813PH9" int(-30) string(10) "3JI9FAGGA9" int(-31) string(10) "2M9S6CDS81" int(-32) string(10) "21D0GNJUVL" int(-33) string(10) "1I4E2IG0HR" int(-34) string(10) "16974O6GH3" int(-35) string(9) "VWQDEH7EJ" int(-36) string(9) "PHPISCOOL"
6 · base · 2 to 62
<? $num = 71915494046709; for($i = 2; $i <= 62; ++$i) { $base = $i; $return = gmp_strval($num, $base); var_dump($base, $return); } ?>
int(2) string(47) "10000010110100000100001011110011111101111110101" int(3) string(30) "100102122001110102121101212210" int(4) string(24) "100112200201132133233311" int(5) string(20) "33411230412433443314" int(6) string(18) "412541304420404033" int(7) string(17) "21101502661262325" int(8) string(16) "2026404136375765" int(9) string(15) "312561412541783" int(10) string(14) "71915494046709" int(11) string(14) "20a0720a613495" int(12) string(13) "8095855546619" int(13) string(13) "31187a9756b01" int(14) string(13) "13a8a2ad61285" int(15) string(12) "84aa48b3c559" int(16) string(12) "41682179fbf5" int(17) string(12) "21b75eed0f03" int(18) string(12) "1229gd73b8d3" int(19) string(11) "bdg7hcbeh47" int(20) string(11) "7093jbhfgf9" int(21) string(11) "46b7j0666cc" int(22) string(11) "2fcb5i909a5" int(23) string(11) "1gl7eg118jb" int(24) string(11) "1357m0d0jcl" int(25) string(10) "il7fleioi9" int(26) string(10) "d69lhi5j01" int(27) string(10) "9bh1cbganl" int(28) string(10) "6m9o6f7445" int(29) string(10) "4rm1813ph9" int(30) string(10) "3ji9fagga9" int(31) string(10) "2m9s6cds81" int(32) string(10) "21d0gnjuvl" int(33) string(10) "1i4e2ig0hr" int(34) string(10) "16974o6gh3" int(35) string(9) "vwqdeh7ej" int(36) string(9) "phpiscool" int(37) string(9) "KHKATELJF" int(38) string(9) "GKKSXbIL7" int(39) string(9) "DH1WHLZYR" int(40) string(9) "AcbJTYJ7T" int(41) string(9) "90AVQDKEQ" int(42) string(9) "7HdS9OHGX" int(43) string(9) "66OOecDUK" int(44) string(9) "55AWd2ZG5" int(45) string(9) "4CKQKhZQd" int(46) string(9) "3R0R4HJLB" int(47) string(9) "30iW1iiYd" int(48) string(9) "2QNkOd4gL" int(49) string(9) "281ZKhKHJ" int(50) string(9) "1g2TT2IY9" int(51) string(9) "1T6nN1l03" int(52) string(9) "1HnPcQbD1" int(53) string(9) "18BYB7LJj" int(54) string(8) "rcMHWMqL" int(55) string(8) "lD2K0eCn" int(56) string(8) "fZjdPM25" int(57) string(8) "aio5HP7j" int(58) string(8) "WX5dsnq9" int(59) string(8) "SqtiqCAk" int(60) string(8) "PfNt2459" int(61) string(8) "Mrql92As" int(62) string(8) "KQ6yq741"
Links
GMP
- gmp_abs
- gmp_add
- gmp_and
- gmp_binomial
- gmp_clrbit
- gmp_cmp
- gmp_com
- gmp_div
- gmp_div_q
- gmp_div_qr
- gmp_div_r
- gmp_divexact
- gmp_export
- gmp_fact
- gmp_gcd
- gmp_gcdext
- gmp_hamdist
- gmp_import
- gmp_init
- gmp_intval
- gmp_invert
- gmp_jacobi
- gmp_kronecker
- gmp_lcm
- gmp_legendre
- gmp_mod
- gmp_mul
- gmp_neg
- gmp_nextprime
- gmp_or
- gmp_perfect_power
- gmp_perfect_square
- gmp_popcount
- gmp_pow
- gmp_powm
- gmp_prob_prime
- gmp_random_bits
- gmp_random_range
- gmp_random_seed
- gmp_root
- gmp_rootrem
- gmp_scan0
- gmp_scan1
- gmp_setbit
- gmp_sign
- gmp_sqrt
- gmp_sqrtrem
- gmp_sub
- gmp_testbit
- gmp_xor