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

Trending Topics

Online now

Members online
1,223
Guests online
3,439
Total visitors
4,662

Forum statistics

Threads
2,308,161
Posts
29,183,609
Members
1,191,869
Latest member
denjiyam
Back
Top