--------------------------------------------------------------------------------------------------------
<?php
if (isset($_POST['decimal'])){
$des = $_POST['decimal'];
$original = $_POST['decimal'];
$oct = '';
if (preg_match('/[^0-9]/',$des)) {
die ("Sepurane sam/mbak, inputan'e salah");
}
else {
while ($des > 0) {
$hasil=$des%8;
case 0: $oct.="0"; break;
case 1: $oct.="1"; break;
case 2: $oct.="2"; break;
case 3: $oct.="3"; break;
case 4: $oct.="4"; break;
case 5: $oct.="5"; break;
case 6: $oct.="6"; break;
case 7: $oct.="7"; break;
case 8: $oct.="8"; break;
case 9: $oct.="9"; break;
case 10: $oct.="A"; break;
case 11: $oct.="B"; break;
case 12: $oct.="C"; break;
case 13: $oct.="D"; break;
case 14: $oct.="E"; break;
case 15: $oct.="F";
default:break;
}
if($des/8 == 0){
$sisa=($des%8);
$des=$sisa;
}
else{
$sisa=($des/8);
$des=$sisa%8;
}
}
$result = strrev($oct);
echo "bilangan $original (desimal) dalam octal adalah $result.
<a href='konversi_inputan_ke_octal.php'>Balik</a> ng awal";
}
}
else {
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>"
method="POST">
<h3>Masukkan Bilangan Desimal disini:
</h3><input type="text" size="50" name="decimal">
<input type="submit" value="Konversikan!">
</form>
<?php
echo $_SERVER['PHP_SELF'];
?>
</body>
</html>
<?php
}
?>
-----------------------------------------------------------------------------------------------------
Dan ini adalah hasil dari Screenshootnya,,
Hasil ScreenShoot |
Setelah Bilangan di Inputkan |
Jika data Input yang dimasukkan Salah |
Tidak ada komentar:
Posting Komentar