This article mainly introduces PHP hexadecimal conversion, and analyzes the implementation skills of mutual conversion between 2,8, 16,36, and 64th to 10th in combination with specific examples. it has some reference value, for more information about PHP conversion, see the example in this article. We will share this with you for your reference. The details are as follows:
You can:
10-hexadecimal conversion: 2, 8, 16, 36, and 62
2, 8, 16, 36, 62 hexadecimal conversion 10 hexadecimal
Note that in hexadecimal conversions of 2, 8, and 16, the system uses its own functions.
Therefore, no matter how high-precision conversion value may be greater than 2147483646.
In addition,
32 hexadecimal low precision conversion, maximum value: 2147483646;
32-digit high-precision conversion, maximum value: 77309411327;
64-in high-precision Conversion. maximum value: 133143986175.
The jinzhi. php file provides the demo function.
Hexadecimal conversion/title> </pead>
= 10) {$ zifu. = chr ($ linshi + 55);} else {$ zifu. = $ linshi;} break; case 62: if ($ linshi >=10) & ($ linshi36) {$ zifu. = chr ($ linshi + 55); break;} if ($ linshi> = 36) & ($ linshi62) {$ zifu. = chr ($ linshi + 61); break;} $ zifu. = $ linshi; break; default: $ zifu. = $ linshi; break;} $ shu = intval ($ shu/$ jinzhi);} for ($ I = strlen ($ zifu); $ I $ w; $ I ++) $ zifu. = "0"; return strrev ($ zifu);} // 2, 8, 16, 36, 62 convert to 10 hexadecimal function jinz Hih_1 ($ zifu, $ jinzhi, $ w) {$ shu = 0; for ($ I = 0; $ I = strlen ($ zifu)-1; $ I ++) {$ linshi = substr ($ zifu, $ I, 1); switch ($ jinzhi) {case 2: $ shu = bindec ($ zifu ); $ I = strlen ($ zifu) + 1; break; case 8: $ shu = octdec ($ zifu); $ I = strlen ($ zifu) + 1; break; case 16: $ shu = hexdec ($ zifu); $ I = strlen ($ zifu) + 1; break; case 36: if (ord ($ linshi) = 57) {$ shu + = (ord ($ linshi)-48) * pow ($ jinzhi, strlen ($ zifu)-$ i-1 );} else {$ shu = $ shu + (o Rd ($ linshi)-55) * pow ($ jinzhi, strlen ($ zifu)-$ i-1);} break; case 62: if (ord ($ linshi) = 57) {$ shu + = $ linshi * pow ($ jinzhi, strlen ($ zifu)-$ i-1);} elseif (ord ($ linshi)> = 65) & (ord ($ linshi) = 90) {$ shu + = (ord ($ linshi)-55) * pow ($ jinzhi, strlen ($ zifu) -$ i-1);} else {$ shu + = (ord ($ linshi)-61) * pow ($ jinzhi, strlen ($ zifu)-$ i-1 );} break;} return $ shu;} // 10 hexadecimal high precision conversion 2, 8, 16, 36, 62 hexadecimal function jinzhih_G0 ($ shu, $ jinzhi, $ w ){ $ Zifu = ""; while ($ shu! = 0) {$ linshi = bcmod ($ shu, $ jinzhi); switch ($ jinzhi) {case 2: $ zifu = decbin ($ shu); return $ zifu; case 8: $ zifu = decoct ($ shu); return $ zifu; case 16: $ zifu = dechex ($ shu); return $ zifu; case 36: if ($ linshi> = 10) {$ zifu. = chr ($ linshi + 55);} else {$ zifu. = $ linshi;} break; case 62: if ($ linshi >=10) & ($ linshi36) {$ zifu. = chr ($ linshi + 55); break;} if ($ linshi> = 36) & ($ linshi62) {$ zifu. = chr ($ lin Shi + 61); break;} $ zifu. = $ linshi; break; default: $ zifu. = $ linshi; break;} $ shu = intval (bcp ($ shu, $ jinzhi);} for ($ I = strlen ($ zifu); $ I $ w; $ I ++) $ zifu. = "0"; return strrev ($ zifu);} // 2, 8, 16, 36, 62 hexadecimal high-precision conversion 10 hexadecimal function jinzhih_G1 ($ zifu, $ jinzhi, $ w) {$ shu = ""; for ($ I = 0; $ I = strlen ($ zifu)-1; $ I ++) {$ linshi = substr ($ zifu, $ I, 1); switch ($ jinzhi) {case 2: $ shu = bindec ($ zifu ); $ I = strlen ($ zifu) + 1; break; case 8: $ shu = octdec ($ zifu); $ I = strlen ($ zifu) + 1; break; case 16: $ shu = hexdec ($ zifu ); $ I = strlen ($ zifu) + 1; break; case 36: if (ord ($ linshi) = 57) {$ shu = bcadd ($ shu, bcmul (ord ($ linshi)-48), bcpow ($ jinzhi, strlen ($ zifu)-$ i-1);} else {$ shu = bcadd ($ shu, bcmul (ord ($ linshi)-55), bcpow ($ jinzhi, strlen ($ zifu)-$ i-1);} break; case 62: if (ord ($ linshi) = 57) {$ shu = bcadd ($ shu, bcmul ($ linshi, bcpow ($ jinzhi, strlen ($ zifu )- $ I-1);} elseif (ord ($ linshi) >=65) & (ord ($ linshi) = 90) {$ shu = bcadd ($ shu, bcmul (ord ($ linshi)-55), bcpow ($ jinzhi, strlen ($ zifu)-$ i-1);} else {$ shu = bcadd ($ shu, bcmul (ord ($ linshi)-61), bcpow ($ jinzhi, strlen ($ zifu)-$ i-1) ;}break ;}return $ shu ;}} if (isset ($ _ GET ["p"]) {if ($ _ GET ["p"] = "1") {echo ""; echo "prompt:"; echo "32 hexadecimal low-precision conversion, maximum value: 2147483646"; echo "32 hexadecimal high-precision conversion, maximum value: 77309411327 "; echo "64-in high-precision conversion, maximum value: 133143 986175 "; echo" "; echo" value: "; $ Fs = new jinzhi_class (); if ($ _ POST ['lx '] = "0" & $ _ POST ['jinzhi0'] = "10 ") {echo $ Fs-> jinzhih_0 ($ _ POST ['zhi'], $ _ POST ['jinzhi1'], $ _ POST ['changdu']). "";} if ($ _ POST ['lx '] = "1" & $ _ POST ['jinzhi0'] = "10 ") {echo $ Fs-> jinzhih_G0 ($ _ POST ['zhi'], $ _ POST ['jinzhi1'], $ _ POST ['changdu']);} if ($ _ POST ['lx '] = "0" & $ _ POST ['jinzhi0']> "10 ") {echo $ Fs-> jinzhih_1 ($ _ POST ['zhi'], $ _ POST ['jinzhi0'], $ _ POST ['changdu']);} if ($ _ POST ['lx '] = "1" & $ _ POST ['jinzhi0']> "10 ") {echo $ Fs-> jinzhih_G1 ($ _ POST ['zhi'], $ _ POST ['jinzhi0'], $ _ POST ['changdu']);} echo "" ;}$ mtime1 = explode ("", microtime (); $ endTime = $ mtime1 [0] + $ mtime1 [1]; printf ("page Execution time: %. 6fs. ", $ endTime-$ startTime);?>
I hope this article will help you with PHP programming.
For more information about PHP hexadecimal conversion examples (conversion from, 64 to 10), please follow the PHP Chinese network!