View Single Post
  #7  
Old 05-25-2002, 11:42 PM
Uranium-235's Avatar
Uranium-235 Uranium-235 is offline
Administrator
 
Join Date: Nov 2001
Location: Mansfield, TX
Posts: 2,469
Send a message via ICQ to Uranium-235 Send a message via AIM to Uranium-235
Default Re: 01000010 01101001 01101110 01100001 01110010 0

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;
}





?>
__________________
PHP...It kicks ASP
Reply With Quote