bin_to_hex
/*
** Usage:
** bin_to_hex(bin)
**
** Arguments:
** bin a string of binary digits, one bit per character
**
** Returns:
** a string of hexadecimal digits, four bits per character
**
** GMLscripts.com
*/
{
var bin,hex,n,h,l,p;
bin = argument0;
hex = "";
n = "0000101100111101000";
h = "0125B6C937FEDA48";
l = string_length(bin);
bin = string_repeat("0",3-(l-1) mod 4)+bin;
for (p=1; p<=l; p+=4) {
hex += string_char_at(h,string_pos(string_copy(bin,p,4),n));
}
return hex;
}
** Usage:
** bin_to_hex(bin)
**
** Arguments:
** bin a string of binary digits, one bit per character
**
** Returns:
** a string of hexadecimal digits, four bits per character
**
** GMLscripts.com
*/
{
var bin,hex,n,h,l,p;
bin = argument0;
hex = "";
n = "0000101100111101000";
h = "0125B6C937FEDA48";
l = string_length(bin);
bin = string_repeat("0",3-(l-1) mod 4)+bin;
for (p=1; p<=l; p+=4) {
hex += string_char_at(h,string_pos(string_copy(bin,p,4),n));
}
return hex;
}
[Please Login]
Projects: 2
Contributor: xot
comments powered by Disqus

Related: