PHP implementation of decimal, 36 binary conversion function

Source: Internet
Author: User
  1. /**
  2. * Binary conversion: decimal, 36 binary conversion
  3. * by bbs.it-home.org
  4. */
  5. $dic = Array (
  6. 0 = ' 0 ', 1 = ' 1 ', 2 = ' 2 ', 3 = ' 3 ', 4 = ' 4 ', 5 = ' 5 ', 6 = ' 6 ', 7 = ' 7 ', 8 = ' 8 ', 9 =&G T ' 9 ',
  7. Ten = ' A ', one by one = ' B ', and ' C ', and ' D ', ' E ', ' F ', ' G ', + ' H ', + ' I ',
  8. + ' J ', + ' K ', + = ' L ', + ' M ', max. ' N ', + ' O ', + ' P ', + = ' Q ' R ',
  9. (+ = ' S ', + = ' T ', + = ' U ', + = ' V ', + = ' W ', + = ' X ', + = ' Y ', + = ' Z ')
  10. );
  11. Decimal Conversion 36 Binary
  12. Function Enid ($int, $format = 8) {
  13. Global $dic;
  14. $arr = Array ();
  15. $loop = true;
  16. while ($loop)
  17. {
  18. $arr [] = $dic [Bcmod ($int, 36)];
  19. $int = Floor (Bcdiv ($int, 36));
  20. if ($int = = 0) {
  21. $loop = false;
  22. }
  23. }
  24. Array_pad ($arr, $format, $dic [0]);
  25. Return implode (", Array_reverse ($arr));
  26. }
  27. 36 Binary Conversion Decimal
  28. function Deid ($id) {
  29. Global $dic;
  30. Key value Exchange
  31. $dedic = Array_flip ($dic);
  32. Go to 0
  33. $id = LTrim ($id, $dic [0]);
  34. Reverse
  35. $id = Strrev ($id);
  36. $v = 0;
  37. for ($i = 0, $j = strlen ($id); $i < $j; $i + +)
  38. {
  39. $v = Bcadd (Bcmul ($dedic [$id {$i}], Bcpow ($i)), $v);
  40. }
  41. return $v;
  42. }
  43. Traverse all three-bit 36 binary numbers
  44. $i = Deid (' ZZZ ');
  45. $b = Array ();
  46. while ($i > 0) {
  47. $id _dym = Str_pad (Enid ($i), 3, 0, str_pad_left);
  48. Echo strtolower ($id _dym), '
    ';
  49. $i--;
  50. }
Copy Code
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.