3v4l.org

run code in 300+ PHP versions simultaneously
<?php $bit1_flag= 1 << 7; $bit2_flag= 1 << 6; // (and i know the fugly for loop should be a do{}while() instead, anyone feel free to fix it, idc) for($i=0;$i<PHP_INT_MAX;++$i){ $str=(string)$i; $hash=hash("sha1",$str,true); $ord=ord($hash[0]); if(($ord & $bit1_flag) || ($ord & $bit2_flag)){ continue; } break; } function strtobits(string $str):string{ $ret=""; for($i=0;$i<strlen($str);++$i){ $ord=ord($str[$i]); for($bitnum=7;$bitnum>=0;--$bitnum){ if($ord & (1<<$bitnum)){ $ret.="1"; }else{ $ret.="0"; } } } return $ret; } var_dump($str,strtobits($hash),bin2hex($hash));
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.30, 7.4.0 - 7.4.23, 8.0.0 - 8.0.11, 8.1rc1 - rc2
string(1) "1" string(160) "0011010101101010000110010010101101111001000100111011000001001100010101000101011101001101000110001100001010001101010001101110011000111001010101000010100010101011" string(40) "356a192b7913b04c54574d18c28d46e6395428ab"

preferences:
70.66 ms | 460 KiB | 5 Q