Label

Jumat, 07 September 2012

Konversi Bilangan Desimal ke Octal,Desimal ke Biner,Desimal ke hexa

                   Konversi Bilangan Desimal ke Octal,Desimal ke         Biner,Desimal ke hexa



Inilah coding konversi desimal ke octal, desimal ke biner, desimal ke hexadesimal dan dilengkapi dengan sistem login.



script untuk validasi atau sistem loginnya :

<!DOCTYPE html>
<?
if(isset($_POST['submit'])){
    $nama=$_REQUEST['nama'];
    if(isset($_POST['gender'])){
        $gender=$_REQUEST['gender'];
}
 else {
$gender='';  
}
$cek='';
}
else{
    $nama='';
    $gender='';
    $cek='harus diisi lengkap';
}
?>



<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
  
    <body background="a.jpg" style=" font-family: arial">
        <marquee  style="font-family:Magneto; font-size: 18; color:"  bgcolor="#FF0000"  loop=100>CREATED BY ARI</marquee><br>
        <h1><?echo $cek ?></h1><br>
       <form action= "<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form1" >
            <p> NAMA : <input type="text" name="nama" value="<?php echo $nama?>" /> </p>
            <p> JENIS KELAMIN :<input type="radio" name="gender" value="L"
                <?php ($gender=="L")? print 'checkked=""' : print ''; ?>/>
            Laki-laki
            <input type="radio" name="gender" value="L"
                <?php ($gender=="P")? print 'checkked=""' : print ''; ?>/>
            Perempuan</p>
            <input type="submit" name="submit" value="submit" />
        </form>
    <?php
    if(isset($_POST['submit'])) {// apakah data anda sudah ter-submit
        // membuat variabel untuk mentimpan data yang dikirim */
     $nama=$_REQUEST['nama'];
     if(isset($_POST['gender'])){
         $gender=$_REQUEST['gender'];
     }
     else{$gender='';
     }
     //cek apakah data yang dikirim tidak kosong
     if($nama==''||$gender==''){
         echo'<h2> maaf data kurang lengkap</h2>';
         echo "<a href='".$_SERVER['PHP_SELF']."'>Reset</a>";
         }
     else{
         if($gender=='L'){
         echo'<h2>Selamat Datang Bro,'.$nama.'!!</h2><br>';
         echo "<a href='gabungan.php'>masuk ke perhitungan :D </a>";
     }
     else{
         echo'<h2>Selamat Datang Sis'.$nama.'!!</h2><br>';
         echo "<a href='gabungan.php'>masuk ke perhitungan :D </a>";
    }
    }
    }
    ?>
    </body>
</html>





Lalu ini adalah script untuk konversinya :



<?php
error_reporting(0);
$des = $_REQUEST['des'];//deklarasi var desimal
$option = $_REQUEST['option'];//deklarasi var pilihan
  function oct($des){        
   echo("jadi octal dari".$des." adalah ".decoct($des) . "<br />");
     
    }
function hexa($bil){  
$decimal=$bil;
$ori=$decimal ;
    $hex =dechex($decimal);
    $result = strrev($hex);
      return "Bilangan $ori (desimal) dalam bentuk hexadesimal adalah $result";
  
}

function bin($bil){
      $decimal= $bil;
      $ori=$decimal;
                $binary= decbin($decimal);
                $result = strrev($binary);
      return "Biner dari : $ori adalah : $result <br/>"; //funngsi ini mereturn hasil
    }

?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Converter Option for Biner by Firayz</title>
    </head>
  
    <body style="font-family:arial" background="a.jpg">
        <marquee  style="font-family:Magneto; color:"  bgcolor="#FF0000"  loop=100>CREATED BY ARI</marquee><br>
        <form action="<?php echo $_SERVER['PHP_SELF']; ?>"
                method="post" name="form1">
            <p>Inputkan : <input type="text" name="des" value="<?php echo $des ?>" /></p>
            <p>Pilih konversi : <br/>
                <input type="radio" name="option" value="bin"
                    <?php ($option=="bin") ? print 'checked=""': print ''; ?>/>
                        Desimal ke Biner<br/>
                <input type="radio" name="option" value="hex"
                    <?php ($option=="hex") ? print 'checked=""': print ''; ?>/>
                        Desimal ke Hexa<br/>
                <input type="radio" name="option" value="oct"
                    <?php ($option=="oct") ? print 'checked=""': print ''; ?>/>
                        Desimal ke Octal<br/>
            </p>
            <input type="submit" name="submit" value="Submit"/>
        </form>
        <?php
            if(isset($_POST['des'])){ //apakah data tersubmit?
                /*mambuat variable untuk menyimpan data yang dikirim*/
                $des = $_REQUEST['des'];
                $option = $_REQUEST['option'];
                //cek apakah data yang dikirim tidak kosong ?
                if($des=='' || $option==''){
                    echo '<h2>Maaf data Kurang Lengkap</h2><br>';
                    echo "<a href='".$_SERVER['PHP_SELF']."'>Reset</a>";
                }
                else{
                    //cek jenis kelamin
                    switch($option){
                        case 'bin' : echo "<h3>".bin($des)."</h3>"; break;
                        case 'hex' : echo "<h3>".hexa($des)."</h3>"; break;
                        case 'oct' : echo "<h3>".oct($des)."</h3>"; break;
                        default : break;
               
                  }
                }
              
              }echo "<br><a href='validator.php'>kembali ke inputan nama </a>";
         ?>
    </body>
</html>

Tidak ada komentar:

Posting Komentar