16 binary string to 36 binary string

Source: Internet
Author: User

Convert the digital base_convert between PHP arbitrary binary
http://php.net/manual/zh/function.base-convert.php

Actual testing due to the problem of loss of precision, will result in a replacement error.
Warning
Due to the use of internal "double" or "float" type, the operation of Base_convert () may result in loss of precision in large values. See the floating point numbers section of this manual for more details.

$s= ' Be55d904-1f35-4838-8f8f-b27edea9dfab ';$sha 1=SHA1($s);Echo $sha 1;Echo' <br/> ';$sha= Str_baseconvert ($sha 1, 16, 36);Echo $sha;Echo' <br/> ';$sha 1= Str_baseconvert ($sha, 36, 16);Echo $sha 1;Echo' <br/> ';functionStr_baseconvert ($str,$frombase=10,$tobase=36) {$str=Trim($str); if(intval($frombase)! = 10) {$len=strlen($str); $q= 0;  for($i= 0;$i<$len;$i++) {$r=Base_convert($str[$i],$frombase, 10); $q=Bcadd(Bcmul($q,$frombase),$r); }}Else $q=$str; if(intval($tobase)! = 10) {$s= ' ';  while(Bccomp($q, ' 0 ', 0) > 0) {$r=intval(Bcmod($q,$tobase)); $s=Base_convert($r, 10,$tobase) .$s; $q=Bcdiv($q,$tobase, 0); }}Else $s=$q; return $s; }

BC Math functions
http://php.net/manual/zh/ref.bc.php

16 binary string to 36 binary string

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.