BELAJAR PHP
Konversi Bilangan Desimal ke Hexa
Pada postingan saya kali ini, saya akan memberikan script php untuk mengkonversikan Bilangan Desimal ke Hexa.
Tutorialnya masih coming soon, sabar ya..
Ini contoh programnya..
Konversi Bilangan Desimal ke Hexa |
Ini Hasilnya..
Konversi Bilangan Desimal ke Hexa |
Script PHP :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
if (isset ($_POST['decimal'])) {
$decimal = $_POST['decimal'];
$original = $_POST['decimal'];
$hex='';
if (preg_match('/[^0-9]/',$decimal)) {
die("Maaf. Inputan salah..");
}
while($decimal>0) {
$result=$decimal%16;
switch($result) {
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($decimal/16==0) {
$sisa=($decimal%16);
$decimal=$sisa;
}else{
$sisa=($decimal/16);
 : $decimal=$sisa%16;
}
}
$result = strrev($hex);
echo "Bilangan $original (desimal) dalam hexa adalah $result.
<a href='konversi_inputan_ke_hexa.php'>Back</a> to the script";
}
else {
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Konversi Desimal Ke Hexa</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>"
method="POST">
<h3>Masukkan bilangan Desimal disini (Cepat !!):
</h3><input type="text" size="50" name="decimal">
<input type="submit" value="Konversikan!">
</form>
<?php
echo $_SERVER ['PHP_SELF'];
?>
?>
</body>
<?php
}
?>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
if (isset ($_POST['decimal'])) {
$decimal = $_POST['decimal'];
$original = $_POST['decimal'];
$hex='';
if (preg_match('/[^0-9]/',$decimal)) {
die("Maaf. Inputan salah..");
}
while($decimal>0) {
$result=$decimal%16;
switch($result) {
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($decimal/16==0) {
$sisa=($decimal%16);
$decimal=$sisa;
}else{
$sisa=($decimal/16);
 : $decimal=$sisa%16;
}
}
$result = strrev($hex);
echo "Bilangan $original (desimal) dalam hexa adalah $result.
<a href='konversi_inputan_ke_hexa.php'>Back</a> to the script";
}
else {
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Konversi Desimal Ke Hexa</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>"
method="POST">
<h3>Masukkan bilangan Desimal disini (Cepat !!):
</h3><input type="text" size="50" name="decimal">
<input type="submit" value="Konversikan!">
</form>
<?php
echo $_SERVER ['PHP_SELF'];
?>
?>
</body>
<?php
}
?>
</html>
Sekian postingan dari saya, Semoga Bermanfaat dan Terimakasih.
0 komentar:
Posting Komentar