3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function gdr_encode($val) { $str = ''; while ($val > 0) { $str .= chr($val & 0xFF); $val = $val >> 8; } return str_replace(array('/', '='), array('_', ''), base64_encode($str)); } function gdr_decode($bin) { $str = base64_decode(str_replace('_', '/', $bin)); $val = 0; for ($i=0; $i<strlen($str); $i++) { $val |= ord($str[$i]) << $i*8; } return $val; } mt_srand(42); for ($i=0; $i<32; $i++) { $val = 1<<$i; $val += mt_rand(0, $val/2); $enc = gdr_encode($val); $dec = gdr_decode($enc); echo "$val => $enc => $dec\n"; }
based on 2DvKA
Output for 7.1.0
1 => AQ => 1 3 => Aw => 3 5 => BQ => 5 12 => DA => 12 16 => EA => 16 38 => Jg => 38 89 => WQ => 89 187 => uw => 187 320 => QAE => 320 529 => EQI => 529 1064 => KAQ => 1064 2162 => cgg => 2162 5556 => tBU => 5556 11563 => Ky0 => 11563 19105 => oUo => 19105 38850 => wpc => 38850 96417 => oXgB => 96417 181973 => 1cYC => 181973 386038 => 9uMF => 386038 554714 => 2nYI => 554714 1377773 => 7QUV => 1377773 2161741 => Tfwg => 2161741 4979519 => P_tL => 4979519 9758324 => dOaU => 9758324 18543681 => QfQaAQ => 18543681 38075565 => rfxEAg => 38075565 73128714 => CttbBA => 73128714 137562497 => gQkzCA => 137562497 378279098 => uhSMFg => 378279098 771855276 => rJMBLg => 771855276 1324587283 => E5nzTg => 1324587283 2652062878 => nkQTng => 2652062878
Output for 5.2.1 - 7.0.14
1 => AQ => 1 3 => Aw => 3 6 => Bg => 6 12 => DA => 12 18 => Eg => 18 35 => Iw => 35 77 => TQ => 77 153 => mQ => 153 276 => FAE => 276 626 => cgI => 626 1459 => swU => 1459 2972 => nAs => 2972 4215 => dxA => 4215 10416 => sCg => 10416 17509 => ZUQ => 17509 43775 => _6o => 43775 85233 => 8UwB => 85233 140435 => kyQC => 140435 300967 => p5cE => 300967 694915 => g5oK => 694915 1059368 => KCoQ => 1059368 3083890 => cg4v => 3083890 6228353 => gQlf => 6228353 11416891 => OzWu => 11416891 18204303 => j8YVAQ => 18204303 49300734 => _kTwAg => 49300734 74233782 => trdsBA => 74233782 200971150 => jpP6Cw => 200971150 292839590 => pmB0EQ => 292839590 537487253 => lWcJIA => 537487253 1172206370 => InPeRQ => 1172206370 2552310675 => kyshmA => 2552310675
Output for 4.3.0 - 5.2.0
1 => AQ => 1 2 => Ag => 2 5 => BQ => 5 12 => DA => 12 23 => Fw => 23 45 => LQ => 45 86 => Vg => 86 183 => tw => 183 361 => aQE => 361 756 => 9AI => 756 1154 => ggQ => 1154 2795 => 6wo => 2795 4424 => SBE => 4424 10352 => cCg => 10352 21771 => C1U => 21771 33286 => BoI => 33286 96321 => QXgB => 96321 179324 => fLwC => 179324 265495 => Fw0E => 265495 618450 => 0m8J => 618450 1395487 => H0sV => 1395487 2585813 => 1XQn => 2585813 5817445 => ZcRY => 5817445 8651313 => MQKE => 8651313 21617831 => p9xJAQ => 21617831 33577821 => XVsAAg => 33577821 95326387 => s5CuBQ => 95326387 182349746 => sm_eCg => 182349746 350435471 => jzjjFA => 350435471 571719102 => vr0TIg => 571719102 1275094591 => P2YATA => 1275094591 2975068922 => +vJTsQ => 2975068922