Kamis, 09 Agustus 2012

Program Konversi dec to hex

   PROGRAM KONVERSI DECIMAL TO HEXA

<?php
if (isset($_POST['decimal'])){
    $decimal = $_POST['decimal'];
    $original = $_POST['decimal'];
    $hexa='';
     if(preg_match('/[^0-9]/',$decimal)){
        die("Sorry Salah INputan...!!!");
    }

    else{
        while($decimal>0){
        $hasil=$decimal%16;
        switch($hasil){
            case 0: $hexa.="0"; break;
            case 1: $hexa.="1"; break;
            case 2: $hexa.="2"; break;
            case 3: $hexa.="3"; break;
            case 4: $hexa.="4"; break;
            case 5: $hexa.="5"; break;
            case 6: $hexa.="6"; break;
            case 7: $hexa.="7"; break;
            case 8: $hexa.="8"; break;
            case 9: $hexa.="9"; break;
            case 10: $hexa.="A"; break;
            case 11: $hexa.="B"; break;
            case 12: $hexa.="C"; break;
            case 13: $hexa.="D"; break;
            case 14: $hexa.="E"; break;
            case 15: $hexa.="F";
            default:break;           
        }
        if($decimal/16==0){
    $sisa=($decimal%16);
    $hexa=$sisa;
}else{
    $sisa=($decimal/16);
    $decimal=$sisa%16;
}}echo strrev($hexa);
    $result = strrev($hexa);
    echo "Bilangan  $original (desimal) dalam hexa adalah $result.
    <a href='Dec_to_hex.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 ="Dec_to_hex.php"
              method="POST">
            <h3>Masukkan Bilangn Binner</h3>
              <input type="text" size="50" name="decimal">
              <input type="submit" value="KOnversikan!">
        </form>
       <?php
        echo "<br>",$_SERVER['PHP_SELF'];
       ?>
       
    </body>
</html>
<?php

?>


Semoga bermamfaat.....:D


 


Tidak ada komentar:

Posting Komentar