Results 1 to 5 of 5

Thread: Ascii to Binary

  1. #1
    j2k
    Guest

    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.

  2. #2
    scoutt
    Guest
    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.

  3. #3
    Addicted Member Martin Wilson's Avatar
    Join Date
    Mar 2002
    Location
    :)
    Posts
    236
    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?

  4. #4
    j2k
    Guest
    ty!

  5. #5
    Addicted Member Martin Wilson's Avatar
    Join Date
    Mar 2002
    Location
    :)
    Posts
    236
    np!
    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
  •  



Click Here to Expand Forum to Full Width