bin_to_bytes
/*
** 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;
}
** 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;
}
[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

Related: