<?php function str2int_mask(string $flags, string $strmask): int { $bitmask = 0; for($i = 0; $i < strlen($strmask); $i++){ if(strpos($flags, $strmask[$i]) === FALSE){ throw new invalidOptionException(); } $bitmask += 2 ** strpos($flags, $strmask[$i]); } return $bitmask; } function int2str_mask(string $flags, int $bitmask): str { $strmask = ''; for($i = 0; $bitmask > 0; $i++){ if($bitmask & 1){ $strmask .= $flags[$i]; } $bitmask = $bitmask >> 1; } return $strmask; } var_dump(str2int_mask('abcd', 'dba'));
You have javascript disabled. You will not be able to edit any code.