hex_to_bytes
/*
** 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;
}
** 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;
}
[Please Login]
Projects: 12
Contributor: xot
comments powered by Disqus

Related: