PHP 16 binary converted to 62 binary

Source: Internet
Author: User
Tags mathematical functions sprintf
62 Binary Press This arrangement:
$dict = ' 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ';

Please write a function input 16 binary, output 62, do not use high-precision mathematical functions, the server is disabled.


Reply to discussion (solution)

51 have gone out to play???

 
  $aide) {$tmp = $output [$index]; $output [$index]= $output [$aide]; $output [$aide]= $tmp; $aide + +; $index--;} $index =0;while ($output [$index]<> '! ') {echo $output [$index]; $index + +;} if (($test + 1)%62==0) echo '
';}? >


I am not very familiar with PHP, many places are from the C-language perspective to think, so some places very awkward. In addition, I cannot guarantee that this thing I write is not wrong, many places in PHP are very vague. The for is to see if there are any errors, and the 62 binary numbers below 3 bits seem to be fine.

In addition I do not know how to make the array into a string, landlord you get it, I do not want to get.

There is a problem with the range of values beyond the integers. If you want to achieve a larger number of conversions, take a look at this:
http://www.php.net/manual/en/book.bc.php

There is a problem with the range of values beyond the integers. If you want to achieve a larger number of conversions, take a look at this:
Http://www.php.net/manual/en/book.bc.php, what's the mess you're in?
They already said not to use high-precision mathematical functions, the server disabled the


There is a problem with the range of values beyond the integers. If you want to achieve a larger number of conversions, take a look at this:
Http://www.php.net/manual/en/book.bc.php, what's the mess you're in?
They already said not to use high-precision mathematical functions, the server disabled the
I forgot that I wrote a few lines of code for a long time, and then I found out that it was going to go wrong when I tried the big numbers.

Landlord you want to convert the hexadecimal number will exceed the maximum value of the shaping data?

This may not require Bcmath, but I didn't try:
Http://phpseclib.bantux.org/code_coverage/220/PHP-5.2/Math_BigInteger.php.html

Landlord you want to convert the hexadecimal number will exceed the maximum value of the shaping data?

No, that 16 binary number is actually a result of a MD5 encryption.


Landlord you want to convert the hexadecimal number will exceed the maximum value of the shaping data?

No, that 16 binary number is actually a result of a MD5 encryption.
MD5 how can so many bits not exceed the representation range of the shaping?
The code in the above link seems to be unable to download, this can be downloaded:
Http://pear.php.net/package/Math_BigInteger/download

No, that 16 binary number is actually the result of a MD5 encryption
So why 62 binary? 64 is not good for binary?
because you just want to tighten up the results of MD5
Test code

$c = MD5 (' FFFF '), Echo $c, Php_eol;echo $r = convert ($c,), Php_eol;echo convert ($r, -64), function convert ($s, $to =64) { c0/> $dict = ' 0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz@= ';  $res = ";  $b = ";  if ($to > 0) {    $to = ceil (log ($to, 2)),//adjust to 2 K-Bindec for    ($i =0; $i
 
  
   
  = $to) {      $res = $dict {(su BSTR ($b,-$to))}. $res;      $b = substr ($b, 0,-$to);    }    $res = $dict {Bindec ($b)}. $res;    return $res;  }  $to = ceil (log (-$to, 2));  for ($i =0; $i
  
   
    
    4) {    $res = $dict {Bindec (substr ($b,-4)}. $res;    $b = substr ($b, 0,-4);  }  if (Bindec ($b)) $res = $dict {Bindec ($b)}. $res;  return $res;}
  
   
 
  
ece926d8c0356205276a45266d361161
3iwirom3ly1itghipjdx5x
ece926d8c0356205276a45266d361161

It's too advanced. The little old man passed by. But also learned a key word, called high precision mathematics. Tonight, under study.

It seems that there is a function, and it can be done by any turn.


No, that 16 binary number is actually a result of a MD5 encryption.
So why would it be 62-binary? 64 is not good for binary?
Because you're just trying to tighten up the results of MD5.
Test code

$c = MD5 (' FFFF '), Echo $c, Php_eol;echo $r = convert ($c,), Php_eol;echo convert ($r, -64), function convert ($s, $to =64) { c0/> $dict = ' 0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz@= ';  $res = ";  $b = ";  if ($to > 0) {    $to = ceil (log ($to, 2)),//adjust to 2 K-Bindec for    ($i =0; $i
 
  
   
  = $to) {      $res = $dict {(su BSTR ($b,-$to))}. $res;      $b = substr ($b, 0,-$to);    }    $res = $dict {Bindec ($b)}. $res;    return $res;  }  $to = ceil (log (-$to, 2));  for ($i =0; $i
  
   
    
    4) {    $res = $dict {Bindec (substr ($b,-4)}. $res;    $b = substr ($b, 0,-4);  }  if (Bindec ($b)) $res = $dict {Bindec ($b)}. $res;  return $res;}
  
   
 
  
ece926d8c0356205276a45266d361161
3iwirom3ly1itghipjdx5x
ece926d8c0356205276a45266d361161



In fact, I want to use 16-bit MD5 to make 4-bit 64 binary short URLs, although there is a great chance of collisions
  • 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.