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

Trending Topics

Online now

Members online
1,331
Guests online
1,163
Total visitors
2,494

Forum statistics

Threads
2,282,224
Posts
29,007,044
Members
1,223,816
Latest member
hieupham97hd
Back
Top