07-03-2008, 10:43 PM
|
#1 (permalink)
|
|
The Wanderer
Join Date: Apr 2008
Posts: 8
Thanks: 0
|
Would you do this differently?
Just threw something together as practice. I'm wondering if you would code this differently. I know it's merely a few lines of code, but I'm sure there are people who can dissect it and code it more eloquently and efficiently than I have. I'm here to learn. Please pick it apart.
PHP Code:
<head>
<title>Byte Calculator</title>
</head>
<body>
<?php
// Constants/Variables
DEFINE('BITS_IN_A_BYTE', 8); // 8 bits in a byte
function convert($bytes)
{
$bits = $bytes * BITS_IN_A_BYTE;
for($x = 0; $x < $bits; $x++)
{
$number += pow(2, $x);
}
return $number;
}
if(!empty($_GET['bytes']))
{
$number = convert($_GET['bytes']);
echo $number;
exit();
}
?>
<fieldset>
<legend>Byte Calculator</legend>
<p>This program will indicate the maximum number a numeric MySQL field can hold as determined by its length in bytes.</p>
<form method="GET">
Bytes: <input type="text" size="5" name="bytes" /><br />
<input type="submit" value="Calculate" />
</form>
</fieldset>
</body>
</html>
|
|
|
|