36) { echo "ERR: Can't convert from base strictly superior to 36"; http_response_code(400); exit(); } $inter = base_convert($input, $fromBase, 10); } $output = $inter; switch ($to) { case 'base64': $output = base64_encode($inter); break; case 'dec': $value = unpack('H*', $inter); $output = base_convert($value[1], 16, 10); break; case 'bin': if (is_numeric($inter)) { $output = decbin($inter); } else { $value = unpack('H*', $inter); $output = base_convert($value[1], 16, 2); } break; case 'hex': if (is_numeric($inter)) { $output = dechex($inter); } else { $output = unpack('H*', $inter)[1]; } break; case 'octal': if (is_numeric($inter)) { $output = decoct($inter); } else { $value = unpack('H*', $inter); $output = base_convert($value[1], 16, 8); } break; } if (preg_match('/^base[0-9]+$/m', $to) && $output === $inter) { $toBase = (int) str_replace('base', '', $to); if ($toBase > 36) { echo "ERR: Can't convert to base strictly superior to 36"; http_response_code(400); exit(); } $output = base_convert($input, 10, $toBase); } echo $output;