oh yeah and the source
Code:
<?php
//binary.php
//binary, the way it should be (ascii -> binary str)
//8-bit ONLY (characters)
switch($convert)
{
case true:
for($i = 0; $i < strlen($ascii); $i++)
$strarr[$i] = ord(substr($ascii, $i, 1));
for($i = 0; $i < count($strarr); $i++)
$binary_str_pre[$i] = dec_2_bin($strarr[$i]);
$ascii_bin_str = implode("/", $binary_str_pre);
?><input type="text" size="150" value="<?php print($ascii_bin_str); ?>"><?php
break;
default:
?>
<title>ASCII to binary</title>
<form action="binary.php" method="post">
<input type="hidden" name="convert" value=true>
String to Convert: <input type="text" name="ascii" size=70><input type="submit">
</form>
<?php
break;
}
function dec_2_bin($dec)
{
$base = 128;
for($i = 0; $i < 8; $i++)
{
if ($dec >= $base)
{
$dec -= $base;
$bin .= '1';
}
else
$bin .= '0';
$base /= 2;
}
return $bin;
}
?>