Om dan Tante" saya mau ngeshare tenteng source code tenteng Decimal to Octal Monggo di Sinau-i
<?php if (isset ($_POST['decimal'])) { $decimal = $_POST['decimal']; $original = $_POST['decimal']; $oct=''; if (preg_match('/[^0-9]/',$decimal)){ die("Maaf, Inputan salah,, <a href='konversi_Des_to_Octal.php'>Coba Lagi</a> to the script"); } else { while($decimal>0){ $hasil=$decimal%8; switch ($hasil){ 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; default:break; } if($decimal/8==0){ $sisa=($decimal%8); $decimal=$isa; } else { $sisa = ($decimal/8); $decimal=$sisa%8; } } } $result = strrev ($oct); echo "DESIMAL : $original <br> OCTAL : $result <br> <a href='konversi_Des_to_Octal.php'>Back</a> to the script"; } else { ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>DESIMAL to OCTAL</title> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <h3>Masukkan bilangan Desimal disini (cepat!!): </h3> <input type="text" size="50" name="decimal"> <input type="submit" value="KONVERSIKAN"> </form> <?php echo $_SERVER['PHP_SELF']; ?> </body> </html> <?php } ?>
Tidak ada komentar:
Posting Komentar