diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/TermMethods.java b/projects/core/src/main/java/dan200/computercraft/core/apis/TermMethods.java index d8716e3a9..07520827d 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/apis/TermMethods.java +++ b/projects/core/src/main/java/dan200/computercraft/core/apis/TermMethods.java @@ -20,12 +20,8 @@ import java.nio.ByteBuffer; */ public abstract class TermMethods { private static int getHighestBit(int group) { - var bit = 0; - while (group > 0) { - group >>= 1; - bit++; - } - return bit; + // Equivalent to log2(group) - 1. + return 32 - Integer.numberOfLeadingZeros(group); } public abstract Terminal getTerminal() throws LuaException; diff --git a/projects/core/src/main/resources/data/computercraft/lua/rom/apis/colors.lua b/projects/core/src/main/resources/data/computercraft/lua/rom/apis/colors.lua index 5494cc1ac..249c69f6f 100644 --- a/projects/core/src/main/resources/data/computercraft/lua/rom/apis/colors.lua +++ b/projects/core/src/main/resources/data/computercraft/lua/rom/apis/colors.lua @@ -367,8 +367,7 @@ colors.toBlit(colors.red) ]] function toBlit(color) expect(1, color, "number") - return color_hex_lookup[color] or - string.format("%x", math.floor(math.log(color) / math.log(2))) + return color_hex_lookup[color] or string.format("%x", math.floor(math.log(color, 2))) end --[[- Converts the given paint/blit hex character (0-9a-f) to a color.