Sabtu, 08 September 2012

Convert Numbers to Binary, Octal, Hexaete with complete options

halooo guys back again with a new post and  new task. This time I share the post that title is  Convert Numbers to Binary, Octal, Hexa
This is her coding












E N J O Y :)




<!DOCTYPE html>
<?php
if(isset($_POST['submit'])){//isset : penekanan form
$nama=$_REQUEST['nama'];
    if(isset($_POST['gender'])){
        $gender=$_REQUEST['gender'];
    }
    else{
        $gender='';
    }
$cek='';
}
else{
    $nama='';
    $gender='';
    $cek='';
}
?>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>convert Numbers to Binary, Octal, Hexa</title>
                <style type="text/css">
            body{
                background: url('hha.jpg') repeat;
            }
            .a{                               
                color:lightcoral;
                text-align: center;
            }
            .b{                
                color:whitesmoke;
                text-align: center;
            }
            form input.highlight{
                background: activeborder;                
                padding: 5px;
            }
            form input.highlight:focus {                
                background: highlight;
            }
        </style>
    </head>
    <body>
       <h1 class='a'><?php echo $cek ?></h1>
<br>
        <form action="konversi_biner.php" method="post" name="form1">
            <p>
<h3 class='b'>
Nama : <input class='highlight' placeholder="input your name" required="required" type="text" name="nama" size ="30" value="<?php echo $nama ?>"/></h3>
</p>
<p>
<h3 class='b'>
gender : <br>
                <input type="radio" name="gender" value="L"
                               <?php ($gender=="L")? print 'checked=""' : print ''; ?>/>
                boys<br>
                <input type="radio" name="gender" value="P"
                       <?php ($gender=="P")? print 'checkMed=""' : print ''; ?>/>
                girl
            </h3>
</p>
<center><input type="submit" name="submit" value="Entry" /></center>
        </form>
    </body>
</html>


after making this coding, making new php web page again in net beans:
checkidot

<!DOCTYPE html><?php
if(isset($_POST['submit1'])){
$decimal=$_REQUEST['decimal'];
    if(isset($_POST['pilih'])){
        $pilih=$_REQUEST['pilih'];
    }
    else{
        $pilih='';
    }
}
else{
    $decimal='';
    $pilih='';
}
?>

<html>
    <head>
                <style type="text/css">
            body{
                background:url('hha.jpg');
            }
            a {
                width: 230px;
                border: 5px solid #9933FF;                
                font:18px;
                font-weight: bolder;
                color: white;
                margin: 20px;
                text-align: center;
                padding: 10px;
                border-radius: 12px;                
                -webkit-border-radius: 12px;
                background: lightblue;                
            }
            a:hover{
                background: purple;
            }
            a:active{
                color: #ffffff;
            }
            .b{
                color: lightgreen;                                
            }
            
                .bayangan1{                               
                font-family:ZirkleOne;
                font-weight:bold;
                color:whitesmoke;
            }
            form input.highlight{
                background: aquamarine;                
                border-radius:5px;
                padding: 5px;
            }
            form input.highlight:focus {
                border: solid 1px #D9AD00;                
                border-radius:5px;
                box-shadow:2px 2px 5px blue;
            }
        </style>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>

    <h1 class="b">
<center>Welcome to The Conversion Numbers</center></h1>
<table border="0" width="900px" heigh="900px" align ="center">
<tr>
    <td align ="center">
    <!-- Proses Pilih Gender dari file Validator.php -->
    <?php
        if(isset ($_POST['submit'])){
            $nama=$_REQUEST['nama'];
            if(isset($_POST['gender'])){
                $gender=$_REQUEST['gender'];
            }
            else{
                $gender='';
            }
        }
        if(isset ($_POST['submit'])){
        if($nama==''|| $gender==''){// tanda || : OR
            echo"<script>
                 alert('Sorry the data are less complete? Fill in Name and Gender');
                 document.location.href='konvers_again.php';
                 </script>";//menggunakan javascript
        }
        else{
            //cek jenis kelamin
            //yang ini pakek petik dua
            if($gender=='L'){
                echo"<br><h1>
Welcome to brother $nama !!</h1>
";
                
            }
            else{
                echo"<br><h1>
Welcome sister $nama !!</h1>
";
            }
        }
        }
    ?>
    <!-- End proses pilih Gender -->
    </td>
    </tr>
</table>                        
    <table border="1" width="900px" heigh="900px" align ="center" class='bayangan1'>
<tr> 
    <td align ="center">
    <p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>
"
          method="POST" name="form1">
        <h2>
 Write down the value of its Decimal numbers: </h2>
<input class='highlight' placeholder="Enter here Decimal Numbers" required="required" type="text" name="decimal" size ="25" value="<?php echo $decimal ?>"/><br>
        <h2>
 Select one Conversions: <br>
        <input type="radio" name="pilih" value="B"
               <?php ($pilih=="B")? print 'checked=""' : print ''; ?>/>
        Biner<br>
        <input type="radio" name="pilih" value="H"
               <?php ($pilih=="H")? print 'checked=""' : print ''; ?>/>
        Hexa<br>
         <input type="radio" name="pilih" value="O"
               <?php ($pilih=="O")? print 'checked=""' : print ''; ?>/>
        Oktal<br>
        </h2>
<input type="submit" name="submit1" value="Konversikan"><br>
    </form>
    <!-- Proses Konversi -->
        <?php
        if(isset($_POST['submit1'])){//isset : penekanan form
        $decimal=$_REQUEST['decimal'];
            if(isset($_POST['pilih'])){
                $pilih=$_REQUEST['pilih'];
            }   
            else{
                $pilih='';
            }
        }
        else{
            $decimal='';
            $pilih='';
        }
        if(isset ($_POST['submit1'])){
        if($decimal==''|| $pilih==''){
            echo"<script>alert('Please select the first conversion what would you do')</script>";//menggunakan javascript
        }
        else{
            if($pilih=='B'){
            //Konversi ke Biner
            if (isset($_POST['decimal'])) {
                $decimal = $_POST['decimal'];
                $original = $_POST['decimal'];
                $binary = '';
                if (preg_match('/[^0-9]/',$decimal)) {
                        die ("Input your wrong !");
                }
                else {
                    while ($decimal > 0) {
                        if ($decimal%2 == 0) {
                            $binary .= 0;
                            $decimal /= 2;
                        }
                        else {
                            $binary .= 1;
                            $decimal = ($decimal/2)-0.5;
                        }
                    }
                    $result = strrev($binary);
                    echo "<br><h2>
decimal numbers : $original if the result is used as Binary $result.</h2>
";
                    }
                }
                else {

                }
            }
            else{
                    if($pilih=='H'){
                    //Konversi ke Hexa
                        if(isset($_POST['decimal'])){
                        $des=$_POST['decimal'];
                        $original=$_POST['decimal'];
                        $hex='';
                        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 "<br><h2>
decimal numbers : $original if the result is used as Hexadecimal $result.</h2>
";
                        }
                    }
                    else{
                        //Konversi ke Oktal
                         if(isset($_POST['decimal'])){
                         $des=$_POST['decimal'];
                         $original=$_POST['decimal'];
                         $octal='';
                         while ($des>0){
                         $hasil=$des%8;
                         switch($hasil){
                         case 0 : $octal.="0"; break;
                         case 1 : $octal.="1"; break;
                         case 2 : $octal.="2"; break;
                         case 3 : $octal.="3"; break;
                         case 4 : $octal.="4"; break;
                         case 5 : $octal.="5"; break;
                         case 6 : $octal.="6"; break;
                         case 7 : $octal.="7";
                         default:break;
                         }
                         if($des/8>0){
                            $sisa=($des/8);
                            $des=$sisa%8;
                            }
                            else{
                            $sisa=($des%8);
                            $des=$sisa;
                            }}
                            $result = strrev($octal);
                            echo "<br><h2>
decimal numbers : $original if the result is used as Octal $result.</h2>
";
                            }
                            else{

                            }
                    }
            }
        }
        }
        echo "<br><h2>
<a href='konvers_again.php'>RESET</a></h2>
<br><br>";
        ?>
    <!-- End proses Konversi -->
    </td>
    </tr>
</table>

    </body>
</html>

and this is the result when you click shift + f6 ====>
1. enter your name and select your gender:

2. for example =>
(if done, please click entry)


3. Write down the value of iys decimal numbers:

4. for example, I enter the number 10 then convert that to Binary :

5. Then will show like above , Enjoy :)



That was was my post, may be useful if there is something wrong please forgive because humans do not escape from mistakes
may be useful, thanks guys 

Tidak ada komentar:

Posting Komentar