进制转换

<?php
$value='';
if (!empty($_POST)){
    $num=$_POST['shi'];
    $se=$_POST['select'];
    if ($se==2){
        $value=decbin($num);
    }
    if ($se==8){
        $value=decoct($num);
    }
    if ($se==16){
        $value=dechex($num);
    }
}
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>进制转换</title>
</head>
<body>
<form action=""method="post">
    十进制:<input type="text" name="shi">
    请选择要转换的进制:<select name="select" id="se">
        <option value="2">二进制</option>
        <option value="8">八进制</option>
        <option value="16">十六进制</option>
    </select>
    <input type="submit" name="submit" value="提交">
    转换结果: <input type="text" value="<?php echo $value;?>">
</form>
</body>
</html>

 

posted @ 2022-06-08 19:48  橙大力  阅读(10)  评论(0)    收藏  举报