Sabtu, 11 Agustus 2012

Konversi Bilangan Desimal ke Hexa

By Intan Della di 9:58:00 AM
Tadikan Konverensi bilangan Desimal ke Oktal sekarang Desimal ke Hexa.

1. Buka aplikasi Neatbeans.
2. Bikin project baru dengan cara klik kanan pada folder >> New >> PHP Web Page.

3. Beri nama file Konversi_Des_to_Oktal.
4. Masukkan script di bawah ini.


<?php
    $self =$_SERVER['PHP_SELF'];
    if(isset($_POST['decimal'])){
    $des=$_POST['decimal'];
    $original=$_POST['decimal'];
    $hex ='';
    if(preg_match('/[^0-9]/',$des)){
        die("Maaf, inputan salah ... <br> <a href='$self'>Back</a> ke awal");
    }
    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";
            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 bentuk hexa adalah $result
        <br> <a href='$self'>Back</a> to the script";
    }
 
 
else {
?>
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Konversi Desimal to Hex</title>
    </head>
    <body>
       <form action="<? echo $_SERVER ['PHP_SELF'];?>"method="post">
           <h1>Masukkan Bilangan Desimal Disini (Cepat !!!) </h1>
           <input type="text" size="50" name='decimal'>
           <input type="submit" value="konversi">
       </form>
   
    </body>
</html>
<?php
}
?>

5. Seperti ini tampilan di Netbeans.



6. Tekan Shift+F6, untuk menjalankan aplikasi. Maka akan tampil di browser seperti ini.

7. Masukkan angka seperti di bawah ini.


 8. Maka akan muncul hasil seperti dibawah ini.


Terimakasih ...

0 komentar:

Posting Komentar

 

d' Vain Copyright © 2013 Design by Inde