Teman-teman Mari Kita Belajar Mengkonversikan
Bilangan ):
Kerjakan di Netbeans yaa ..
1. Masukkan coding berikut dan beri nama Login.php
<?php
if(isset($_POST['submit'])){
$nama=$_REQUEST['name'];
if(isset($_POST['gender'])){
$gender=$_REQUEST['gender'];
}
else{
$gender='';
}
$cek='';
}
else{
$nama='';
$gender='';
$cek='Silahkan Masukkan Data Anda Dengan Lengkap dan Benar :)';
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>PHP - keonversi bilangan</title>
<style type="text/css">
body{
background-image: url('tugas.jpg');
}
.a{
font-family:Comic Sans MS;
font-weight:bold;
color:blue;
text-align: center;
}
.b{
font-family:Comic Sans MS;
font-weight:bold;
color:blue;
text-align: center;
}
form input.highlight{
background: white;
padding: 5px;
text-align: center;
}
form input.highlight:focus {
background: white;
text-align: center;
}
</style>
</head>
<body>
<h1 class='a'>
<?php echo $cek ?></h1>
<br>
<form action="g.php" method="post" name="form1">
<p>
<h3 class='b'>
Nama : <input class='highlight' placeholder="Nama Lengkap Anda"
required="required" type="text" name="nama" size ="30" value="<?php
echo $nama ?>"/></h3>
</p>
<p>
<h3 class='b'>
Jenis Kelamin :
<input type="radio" name="gender" value="L"
<?php ($gender=="L")? print
'checked=""' : print ''; ?>/>
Cowok
<input type="radio" name="gender" value="P"
<?php ($gender=="P")? print 'checked=""' :
print ''; ?>/>
Cewek
</h3>
</p>
<center><input type="submit" name="submit" value="Enter"></center>
</form>
</body>
</html>
if(isset($_POST['submit'])){
$nama=$_REQUEST['name'];
if(isset($_POST['gender'])){
$gender=$_REQUEST['gender'];
}
else{
$gender='';
}
$cek='';
}
else{
$nama='';
$gender='';
$cek='Silahkan Masukkan Data Anda Dengan Lengkap dan Benar :)';
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>PHP - keonversi bilangan</title>
<style type="text/css">
body{
background-image: url('tugas.jpg');
}
.a{
font-family:Comic Sans MS;
font-weight:bold;
color:blue;
text-align: center;
}
.b{
font-family:Comic Sans MS;
font-weight:bold;
color:blue;
text-align: center;
}
form input.highlight{
background: white;
padding: 5px;
text-align: center;
}
form input.highlight:focus {
background: white;
text-align: center;
}
</style>
</head>
<body>
<h1 class='a'>
<?php echo $cek ?></h1>
<br>
<form action="g.php" method="post" name="form1">
<p>
<h3 class='b'>
Nama : <input class='highlight' placeholder="Nama Lengkap Anda"
required="required" type="text" name="nama" size ="30" value="<?php
echo $nama ?>"/></h3>
</p>
<p>
<h3 class='b'>
Jenis Kelamin :
<input type="radio" name="gender" value="L"
<?php ($gender=="L")? print
'checked=""' : print ''; ?>/>
Cowok
<input type="radio" name="gender" value="P"
<?php ($gender=="P")? print 'checked=""' :
print ''; ?>/>
Cewek
</h3>
</p>
<center><input type="submit" name="submit" value="Enter"></center>
</form>
</body>
</html>
2. Selanjutnya buat new project dengan nama Konverter.php . Tulis coding seperti berikut .
<?php
if(isset($_POST['submit1'])){
$decimal=$_REQUEST['decimal'];
if(isset($_POST['pilih'])){
$pilih=$_REQUEST['pilih'];
}
else{
$pilih='';
}
}
else{
$decimal='';
$pilih='';
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Konversi Bilangan Desimal</title>
<style type="text/css">
body{
background-image: url('tugas.jpg');
}
.a{
font-family:Comic Sans MS;
font-weight:bold;
color:blue;
text-align: center;
}
.b{
font-family:Comic Sans MS;
font-weight:bold;
color:blue;
text-align: center;
}
</style>
</head>
<body>
<h1 class="b"Numbers>Konversi Bilangan</h1>
<?php
if(isset ($_POST['submit'])){
$nama=$_REQUEST['nama'];
if(isset($_POST['gender'])){
$gender=$_REQUEST['gender'];
}
else{
$gender='';
}
}
if(isset ($_POST['submit'])){
if($nama==''|| $gender==''){
echo"<script>
alert('Maap , data yang anda masukkan tidak lengkap . ');
document.location.href='l.php';
</script>";
}
else{
if($gender=='L'){
echo"<br><h3 class='a'>
Selamat Datang Tuan, $nama</h3>";
}
else{
echo"<h3 class='a'>Selamat Datang Nyonya, $nama</h1>";
}
}
}
?>
<!-- End proses pilih Gender -->
<form action="g.php" method="POST" name="form1">
<h3 class='a'>Masukkan Angka : <input class='highlight' placeholder="Masukkan Angka" required="required" type="text" name="decimal" size ="25" value="<?php echo $decimal ?>"/><br></h3>
<h2><h3 class='a'>Konversi ke: <br></h3>
<h3 class='a'><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></h3>
<h3 class='a'><input type="submit" name="submit1" value="Convert"><br></a>
</form>
<?php
if(isset($_POST['submit1'])){
$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 convert to?')</script>";
}
else{
if($pilih=='B'){
if (isset($_POST['decimal'])) {
$decimal = $_POST['decimal'];
$original = $_POST['decimal'];
$binary = '';
if (preg_match('/[^0-9]/',$decimal)) {
die ("Masukkan Angka , Jangan yang Lain");
}
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><h3 class='a'>$original Binernya adalah $result.</h3>
";
}
}
else {
}
}
else{
if($pilih=='H'){
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><h3 class='a'>$original Hexanya Adalah $result.</h3>
";
}
}
else{
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><h3 class='a'>$original Oktalnya adalah $result.</h3>
";
}
else{
}
}
}
}
}
echo "<br><h2 class='a'><a href='g.php'>Reset</a></h2><br><br>";
?>
<!-- End proses Konversi -->
</td>
</tr>
</table>
</body>
</html>
if(isset($_POST['submit1'])){
$decimal=$_REQUEST['decimal'];
if(isset($_POST['pilih'])){
$pilih=$_REQUEST['pilih'];
}
else{
$pilih='';
}
}
else{
$decimal='';
$pilih='';
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Konversi Bilangan Desimal</title>
<style type="text/css">
body{
background-image: url('tugas.jpg');
}
.a{
font-family:Comic Sans MS;
font-weight:bold;
color:blue;
text-align: center;
}
.b{
font-family:Comic Sans MS;
font-weight:bold;
color:blue;
text-align: center;
}
</style>
</head>
<body>
<h1 class="b"Numbers>Konversi Bilangan</h1>
<?php
if(isset ($_POST['submit'])){
$nama=$_REQUEST['nama'];
if(isset($_POST['gender'])){
$gender=$_REQUEST['gender'];
}
else{
$gender='';
}
}
if(isset ($_POST['submit'])){
if($nama==''|| $gender==''){
echo"<script>
alert('Maap , data yang anda masukkan tidak lengkap . ');
document.location.href='l.php';
</script>";
}
else{
if($gender=='L'){
echo"<br><h3 class='a'>
Selamat Datang Tuan, $nama</h3>";
}
else{
echo"<h3 class='a'>Selamat Datang Nyonya, $nama</h1>";
}
}
}
?>
<!-- End proses pilih Gender -->
<form action="g.php" method="POST" name="form1">
<h3 class='a'>Masukkan Angka : <input class='highlight' placeholder="Masukkan Angka" required="required" type="text" name="decimal" size ="25" value="<?php echo $decimal ?>"/><br></h3>
<h2><h3 class='a'>Konversi ke: <br></h3>
<h3 class='a'><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></h3>
<h3 class='a'><input type="submit" name="submit1" value="Convert"><br></a>
</form>
<?php
if(isset($_POST['submit1'])){
$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 convert to?')</script>";
}
else{
if($pilih=='B'){
if (isset($_POST['decimal'])) {
$decimal = $_POST['decimal'];
$original = $_POST['decimal'];
$binary = '';
if (preg_match('/[^0-9]/',$decimal)) {
die ("Masukkan Angka , Jangan yang Lain");
}
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><h3 class='a'>$original Binernya adalah $result.</h3>
";
}
}
else {
}
}
else{
if($pilih=='H'){
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><h3 class='a'>$original Hexanya Adalah $result.</h3>
";
}
}
else{
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><h3 class='a'>$original Oktalnya adalah $result.</h3>
";
}
else{
}
}
}
}
}
echo "<br><h2 class='a'><a href='g.php'>Reset</a></h2><br><br>";
?>
<!-- End proses Konversi -->
</td>
</tr>
</table>
</body>
</html>
3. Run Konverter.php dengan cara Shift+F6 .
0 komentar:
Posting Komentar