You are currently viewing the GMLscripts.com static mirror. Forum access and script submissions are not available through this mirror.

Invert GMLscripts.com

bin_to_hex

Converts a string of binary digits to a string of hexadecimal digits.

hex = bin_to_hex("00100");  //  hex == "04"
hex = bin_to_hex("10101");  //  hex == "15"
hex = bin_to_hex("11111");  //  hex == "1F"
bin_to_hex(bin)
Returns a string of hexadecimal digits representing the given binary string.
COPY/// bin_to_hex(bin)
//
//  Returns a string of hexadecimal digits 
//  representing the given binary string.
//
//      bin         binary digits, string
//
/// GMLscripts.com/license
{
    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;
}

contributes: xot

GitHub: View · Commits · Blame · Raw