Important alert: (current site time 7/15/2013 9:57:11 AM EDT)
 

article

ASCII to BINARY and visa-versa

Email
Submitted on: 3/9/2005 10:28:10 PM
By: Ryan Cheeseman  
Level: Advanced
User Rating: By 3 Users
Compatibility: PHP 3.0, PHP 4.0
Views: 28709
 
     This really does not have much a purpose other then to amuse my self and anyone else thats intrested, its 2 functionsto convert ascii text to binary and binary back to ascii, have you ever seen this page http://nickciske.com/tools/binary.php? its been featured on The Screen Savers, and after i saw it i always wondered how it was done, well this is how. It's nothing too special but leave your comments and please vote, i'd like to know what everyone thinks, thanks

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				to convert ascii text use this function
function asc2bin($in)#syntax - asc2bin("text to convert");
{
 $out = '';
 for ($i = 0, $len = strlen($in); $i < $len; $i++)
 {
$out .= sprintf("%08b",ord($in{$i}));
 }
 return $out;
}
use this function to convert binary back to readable ascii text
function bin2asc($in)#syntax - bin2asc("binary to convert");
{
 $out = '';
 for ($i = 0, $len = strlen($in); $i < $len; $i += 8)
 {
$out .= chr(bindec(substr($in,$i,8)));
 }
 return $out; 
}
have fun with it and please give credit if you use these functions :)
Ryan Cheeseman
~~Dull1554
~~~~Dull1554@gmail.com


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Advanced category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

12/4/2005 7:51:42 AMusman

Hi there, pls. i want u 2 assist me on how 2 compile my codes.

Thanx
(If this comment was disrespectful, please report it.)

 
4/23/2007 12:05:54 AMAmila

Itz d best site i hv visited
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.