Sabtu, 11 Agustus 2012

Konversi Desimal to Hexa

Tugas posting yg terakhir nih.... Konversi Desimal to Hexa, yoyoyo,

1. Buka NeatBeans
2. Klik kanan pada Source File, lalu pilih PHP Web Page

3. Beri nama Konversi_Des_ke_Hexa

4. Lalu ketikkan syntax berikut

<?php
if (isset($_POST['decimal'])) {
    $des = $_POST['decimal'];
    $original = $_POST['decimal'];
    $hex='';
     if (preg_match('/[^0-9]/',$des)){
        die("Maf inputan salah");
    }
    else {
        while($des > 0) {
            $hasil=$des%16;
           switch($hasil) {
               case 0: $hex.="0"; break;
               case 1: $hex.="1"; break;
               case 2: $hex.="2"; break;
               case 3: $hex.="3"; break;
               case 4: $hex.="4"; break;
               case 5: $hex.="5"; break;
               case 6: $hex.="6"; break;
               case 7: $hex.="7"; break;
               case 8: $hex.="8"; break;
               case 9: $hex.="9"; break;
               case 10: $hex.="A"; break;
               case 11: $hex.="B"; break;
               case 12: $hex.="C"; break;
               case 13: $hex.="D"; break;
               case 14: $hex.="E"; break;
               case 15: $hex.="F"; break;
               default:break;
           }
           if($des/16 == 0) {
               $sisa=($des%16);
               $des=$sisa;
           }
           else {
               $sisa=($des/16);
               $des=$sisa%16;
           }
        }
        $result = strrev($hex);
        echo "bilangan $original (desimal) dalam hexa adalah $result.
        <a href='Konversi_Des_ke_Hexa.php'>Back</a> to the script";
    }
}
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 :   </h3>
            <input type="text" size="50" name="decimal">
            <input type="submit" value="KONVERSIKAN">
        </form>
        <?php
        echo $_SERVER['PHP_SELF']
        ?>
    </body>
</html>
<?php
}
?>

5. Klik Shift + f6, maka pada browser akan muncul tampilan seperti ini

6. Masukkan input, terserah, lalu klik konversikan


7. Hasilnya akan muncul seperti ini. Klik Back

8. Dan tampilan akan kembali seperti awal

Done! uyeyeye :3 gampang kan? yuk mari dicoba yaa. Sincerely~ and Happy Holiday ({})

Tidak ada komentar:

Posting Komentar