Pixel-Composer/scripts/bin_function/bin_function.gml

24 lines
486 B
Plaintext
Raw Normal View History

2023-01-17 08:11:55 +01:00
function bin_fraction(intVal, len) {
var amp = 1;
var val = 0;
for( var i = len - 1; i >= 0; i-- ) {
var _b = (intVal & ~(1 << len)) >> len;
amp *= 0.5;
val = amp * _b;
}
return val;
}
function dec_to_hex(dec, len = 1) {
2023-06-24 22:12:35 +02:00
static dig = "0123456789ABCDEF";
2023-01-17 08:11:55 +01:00
var hex = "";
2024-01-10 06:36:33 +01:00
if (dec < 0) len = max(len, ceil(logn(16, 2 * abs(dec))));
2023-01-17 08:11:55 +01:00
while (len-- || dec) {
hex = string_char_at(dig, (dec & $F) + 1) + hex;
dec = dec >> 4;
}
2024-01-10 06:36:33 +01:00
2023-01-17 08:11:55 +01:00
return hex;
}