hex_to_bytes

Downloadhex_to_bytes(hex)   Returns a string of bytes converted from the given string of hexadecimal digits.
/*
**  Usage:
**      hex_to_bytes(hex)
**
**  Arguments:
**      hex     a string of hexadecimal digits, four bits per character
**
**  Returns:
**      a string of bytes, eight bits per character
**
**  GMLscripts.com
*/

{
    var hex,str,h,l,p,hi,lo;
    hex = string_upper(argument0);
    str = "";
    h = "0123456789ABCDEF";
    l = string_length(hex);
    if (l mod 2) hex = "0"+hex;
    for (p=1;p<=l;p+=2) {
        hi = string_pos(string_char_at(hex,p),h)-1;
        lo = string_pos(string_char_at(hex,p+1),h)-1;
        str += chr(hi << 4 | lo);
    }
    return str;
}

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


comments powered by Disqus