bin_to_bytes

Downloadbin_to_bytes(bin)   Returns a string of bytes converted from the given string of binary digits.
/*
**  Usage:
**      bin_to_bytes(bin)
**
**  Arguments:
**      bin     a string of binary digits, one bit per character
**
**  Returns:
**      a string of bytes, eight bits per character
**
**  GMLscripts.com
*/

{
    var bin,str,p,byte;
    bin = argument0;
    str = "";
    p = string_length(bin);
    repeat (ceil(p/8)) {
        byte = 0;
        repeat (8) {
            byte = byte >> 1;
            if (p) if (string_char_at(bin,p) == "1") byte = byte | 128;
            p -= 1;
        }
        str = chr(byte) + str;
    }
    return str;
}

Click if you've used this script[Please Login]
Projects: 0

 Contributor: xot

 History:
Mar 23, 2007 - xot submits the original script
Feb 26, 2008 - xot corrects a major bug found by $pector


comments powered by Disqus