🔒 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
  • 662
    Views
  • 2
    Participants
Last reply from:
0xLouis

Trending Topics

Online now

Members online
1,212
Guests online
2,087
Total visitors
3,299

Forum statistics

Threads
2,294,538
Posts
29,091,683
Members
1,207,377
Latest member
christer0763218
Back
Top