🔒 Closed Pa help po Decimal to Bin, Oct, Hex

Status
Not open for further replies.

kiplog

Leecher
Problem: Create a simple web application that converts decimal into binary, octal, hexadecimal using functions and arrays.

Pa help naman po pano ayusin yung code ko, yun sanang mag iinput ng decimal tsaka lang lalabas yung answer sa binary, octal, hexadecimal.

PHP:
<!DOCTYPE html>
<html>
<body>

<?php
function decToBin($n)
{
 $binary;
 $i = 0;
 while ($n != 0)
 {
  $binary[$i] = $n % 2;
  $n = (int)($n / 2);
  $i++;
 }
 for ( $j = $i - 1; $j >= 0; $j--)
  echo $binary[$j];
}
$n = 33;
 decToBin($n);
?>

<?php
function decToOctal($n)
{
 $octal;
 $i = 0;
 while ($n != 0)
 {
  $octal[$i] = $n % 8;
  $n = (int)($n / 8);
  $i++;
 }
 for ( $j = $i - 1; $j >= 0; $j--)
  echo $octal[$j];
}
$n = 33;
decToOctal($n);
?>

<?php
function decToHex($n)
{
 $hexadecimal;
 $i = 0;
 while ($n != 0)
 {
  $hexadecimal[$i] = $n % 16;
  $n = (int)($n / 16);
  $i++;
 }
 for ( $j = $i - 1; $j >= 0; $j--)
  echo $hexadecimal[$j];
}
$n = 33;
decToHex($n);
?>

</body>
</html>
 
Status
Not open for further replies.

About this Thread

  • 1
    Replies
  • 655
    Views
  • 2
    Participants
Last reply from:
0xLouis

Trending Topics

Online now

Members online
1,028
Guests online
1,264
Total visitors
2,292

Forum statistics

Threads
2,272,389
Posts
28,942,402
Members
1,237,177
Latest member
pinkpototoy
Back
Top