Selasa, 14 Agustus 2012

Decimal to Biner Converter

 Kali ini saya akan membuat tutorial kecil tentang bagaimana cara membuat Konversi Bilangan Desimal ke Biner, Ikuti langkah2 nya ok.. :)

Buka Program NetBeans, New Project - PHP
Arahkan cursor ke Project lalu klik kanan pilih New - PHP web page
Lalu tuliskan Sintax seperti di bawah ini
<?php
if (isset($_POST['decimal'])) {//apakah data ter-submit?
    $decimal =$_POST['decimal'];
    $original=$_POST['decimal'];
    $binary='';
    if (preg_match('/[^0-9]/', $decimal)){//memastikan inputan adalah angka
        die("Maaf. Inputan salah...");
    }
    else
    {
        while ($decimal>0){//looping memutuskan apakah 1 atau 0 yang ditambah
            if($decimal%2 ==0){  //menambah 0
            $binary .=0 ;//$binary=0+binary;
            $decimal /=2;//$binary=binary/2;
        }
        else{//menambah 1
            $binary .=1;//$binary=1+binary;
            $decimal = ($decimal/2)-0.5;
        }
    }
$result =  strrev($binary);//hasil dibalik
echo "Bilangan $original (desimal) dalam biner adalah $result.
<a href='konversi_inputan_ke_biner.php'>Back</a>to the script";//hasil
    }
}
else{
    ?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Konversi Desimal ke Biner</title>
    </head>
    <body> tes
        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
            <h3>Masukan Bilangan Desimal disini (cepat!!):</h3>
            <input type ="text" size="50" name="decimal">
            <input type="submit" value="Konversikan!">
        </form>
        <?php
        echo "<br>",$_SERVER['PHP_SELF'];
        ?>
    </body>
</html>
<?php
}
?>

    4. Apabila sudah selesai run program dengan cara tekan Shift + f6

Rabu, 08 Agustus 2012

Decimal to Hexa Converter

ini kodingnya buisa dicoba sendiri....

<?php
//$des= 1 ;
//$hex="0";
//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;
//         }
//} echo strrev($hex);
// coding di atas gagal sob, hehehe


if (isset ($_POST['decimal'])) {
    $decimal = $_POST['decimal'];
    $original = $_POST['decimal'];
    if (preg_match('/[^0-9]/', $decimal)){
        die("Maaf, inputan salah ...");
    }
    else {

          $hex = dechex($decimal);
         
   
      $result = strrev($hex);
      echo "<h2>Bilangan $original (desimal) dalam bentuk hexadesimal adalah $result<h2>
      <h2><a href='konversi_inputan_ke_biner.php'>Back</a> to the script</H2>";
        }
}
else {
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></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"> <br>
           <input type="submit" value="konversi">
   
       </form>
   
    </body>
</html>
<?php
}
?>

DECIMAL TO OCTAL CONVERTER

ini coding Decimal To Octal Converternya bisa dicoba



<?php
if (isset ($_POST['decimal'])) {
    $decimal = $_POST['decimal'];
    $original = $_POST['decimal'];
    if (preg_match('/[^0-9]/', $decimal)){
        die("Maaf, inputan salah ...");
    }
    else {
 
          $oct = decoct($decimal);
   
      echo "<h2>Bilangan $original (desimal) dalam bentuk octal adalah $oct<h2>
      <h2><a href='".$_SERVER['PHP_SELF']."'>Back</a> to the script</H2>";
        }
}
else {
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></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"> <br>
           <input type="submit" value="konversi">
     
       </form>
   
    </body>
</html>
<?php
}
?>

Konversi Bilangan Desimal

DECIMAL TO BINER
pada fungi decbin bilangan yang asli nya desimal diubah ke dalam bentuk biner, untuk lebih jelasnya aku akan tulis script dibawah ini :
<?
$num=13; //mendefinisikan angka yang akan di tampilkan
$biner= decbin($num); //mengubah dari desimal ke biner
echo "Desimal= ".$num." Biner= ".$biner; //hasilnya adalah Desimal= 13 Biner= 1011
?>


DECIMAL TO OCTAL
pada fungi decoct bilangan yang asli nya desimal diubah ke dalam bentuk biner, untuk lebih jelasnya aku akan tulis script dibawah ini :
<?
$num=13; //mendefinisikan angka yang akan di tampilkan
$oct= decoct($num); //mengubah dari desimal ke biner
echo "Desimal= ".$num." Octal= ".$oct; //hasilnya adalah Desimal= 13 Octal= 15
?>

DECIMAL TO HEXA
pada fungi dechex bilangan yang asli nya desimal diubah ke dalam bentuk biner, untuk lebih jelasnya aku akan tulis script dibawah ini :
<?
$num=13; //mendefinisikan angka yang akan di tampilkan
$hex= dechex($num); //mengubah dari desimal ke biner
echo "Desimal= ".$num." Hexadesimal= ".$hex; //hasilnya adalah Desimal= 13 Hexadesimal= d
?>