Just a stupid little script i made when i was bored that can convert a number to binary form and vice versa. There is a working example here:
http://www.schooliez.com/binary.php
By : D1NGO
<?php
if($_GET['t'] == "b1")
{
if($Submit1)
{
makeBinary($binary);
}
else
{
echo <<<FORM
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">Please only choose numbers smaller than 255</font>
<form name="form1" method="post" action="$PHP_SELF?t=b1">
<p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Convert this number:</font>
<input type="text" name="binary">
</p>
<p>
<input type="submit" name="Submit1" value="Convert">
</p>
</form>
FORM;
}
}
elseif($_GET['t'] == "b2")
{
if($Submit2)
{
if($num1 == 1)
{
$number = 128;
}
if($num2 == 1)
{
$number += 64;
}
if($num3 == 1)
{
$number += 32;
}
if($num4 == 1)
{
$number += 16;
}
if($num5 == 1)
{
$number += 8;
}
if($num6 == 1)
{
$number += 4;
}
if($num7 == 1)
{
$number += 2;
}
if($num8 == 1)
{
$number += 1;
}
echo "<font face=\"Verdana\" size=\"2\">The converted number is: $number</font>";
}
else{
echo <<<FORM
<font face="Verdana" size="2">Place the number "1" or "0" in the boxes</font>
<form name="form1" method="post" action="$PHP_SELF?t=b2">
<table width="431" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td height="25" colspan="2" valign="top"> <input name="num1" type="text" size="1" maxlength="1">
<input name="num2" type="text" size="1" maxlength="1"> <input name="num3" type="text" size="1" maxlength="1">
<input name="num4" type="text" size="1" maxlength="1"> <input name="num5" type="text" size="1" maxlength="1">
<input name="num6" type="text" size="1" maxlength="1"> <input name="num7" type="text" size="1" maxlength="1">
<input name="num8" type="text" size="1" maxlength="1"> </td>
</tr>
<tr>
<td width="110" height="24" valign="top"><input type="submit" name="Submit2" value="Convert"></td>
<td width="321"> </td>
</tr>
<tr>
<td height="25"> </td>
<td> </td>
</tr>
</table>
</form>
FORM;
}
}
else
{
echo <<<FORM
<table width="591" border="0" cellpadding="5" cellspacing="1" bgcolor="#000000">
<!--DWLayoutTable-->
<tr>
<td height="32" colspan="3" valign="middle" bgcolor="#FFFFFF"><div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Binary
Conversions</font></div></td>
</tr>
<tr>
<td width="140" height="24" valign="top" bgcolor="#FFFFFF"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Decimal
to Binary:</font></td>
<td width="89" valign="top" bgcolor="#FFFFFF"><form name="form1" method="post" action="$PHP_SELF?t=b1"><input type="submit" name="Submit" value="Go"></form></td>
<td width="328" rowspan="3" valign="top" bgcolor="#FFFFFF"><font color="#CC0000" size="1" face="Verdana, Arial, Helvetica, sans-serif">Project
designed and created by Rowan Hemsley</font></td>
</tr>
<tr>
<td height="24" valign="top" bgcolor="#FFFFFF"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Binary
to Decimal:</font></td>
<td valign="top" bgcolor="#FFFFFF"><form name="form1" method="post" action="$PHP_SELF?t=b2"><input type="submit" name="Submit" value="Go"></form></td>
</tr>
<tr>
<td height="2"></td>
<td></td>
</tr>
</table>
FORM;
}
function makeBinary($x)
{
if(($x - 128) >= 0)
{
$binary = '1';
$x = $x - 128;
}
else
{
$binary = '0';
}
if(($x - 64) >= 0)
{
$binary = "$binary 1";
$x = $x - 64;
}
else
{
$binary = "$binary 0";
}
if(($x - 32) >= 0)
{
$binary = "$binary 1";
$x = $x - 32;
}
else
{
$binary = "$binary 0";
}
if(($x - 16) >= 0)
{
$binary = "$binary 1";
$x = $x - 16;
}
else
{
$binary = "$binary 0";
}
if(($x - 8) >= 0)
{
$binary = "$binary 1";
$x = $x - 8;
}
else
{
$binary = "$binary 0";
}
if(($x - 4) >= 0)
{
$binary = "$binary 1";
$x = $x - 4;
}
else
{
$binary = "$binary 0";
}
if(($x - 2) >= 0)
{
$binary = "$binary 1";
$x = $x - 2;
}
else
{
$binary = "$binary 0";
}
if(($x - 1) >= 0)
{
$binary = "$binary 1";
$x = $x;
echo "<font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">$binary</font>";
}
else
{
$binary = "$binary 0";
echo "<font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">$binary</font>";
}
}
?>
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.
More Miscellaneous Code Articles More By Codewalkers
Please enable JavaScript to view the comments powered by Disqus. blog comments powered by