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("01110"); // hex == "0E"
hex = bin_to_hex("11111"); // hex == "1F"
hex = bin_to_hex("01010101"); // hex == "55"
hex = bin_to_hex("10101010"); // hex == "AA"
- bin_to_hex(bin)
- Returns a hexadecimal string converted from a binary string.
COPY/// @func bin_to_hex(bin)
///
/// @desc Returns a hexadecimal string converted from a binary string.
///
/// @param {string} bin binary digits
///
/// @return {string} hexadecimal digits
///
/// GMLscripts.com/license
function bin_to_hex(bin)
{
var hex = "";
var nib = "0000101100111101000";
var dig = "0125B6C937FEDA48";
var len = string_length(bin);
bin = string_repeat("0", -len & 3) + bin;
for (var pos = 1; pos <= len; pos += 4) {
hex += string_char_at(dig, string_pos(string_copy(bin, pos, 4), nib));
}
return hex;
}
Contributors: xot
GitHub: View · Commits · Blame · Raw