|
-
May 30th, 2002, 02:57 PM
#1
Ascii to Binary
Hi all,
How can you convert an ascii string (such as "Hello World") to binary 0 and 1s in PHP?
Thanks in advance.
-
May 31st, 2002, 08:09 AM
#2
in php you would have to make a function yourself and convert all letters to hex then go to binary. that would be pretty hard to come up with.
-
May 31st, 2002, 10:14 AM
#3
Addicted Member
This seems to work but I am sure there is an easier method:
PHP Code:
<?
$DecString = "Hello World";
for ($i = 0; $i <= strlen($DecString); $i++) {
$char = substr($DecString,$i,1);
$dec = ord($char);
$bin = base_convert($dec, 10, 2);
$bin = str_pad($bin, 8, "0", STR_PAD_LEFT);
print $bin;
}
?>
What is the answer to this question?
-
May 31st, 2002, 10:21 AM
#4
-
May 31st, 2002, 10:30 AM
#5
Addicted Member
What is the answer to this question?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|