```\nfunction log2(uint256 value) internal pure returns (uint256) {\n    uint256 result = 0;\n    unchecked {\n        if (value >> 128 > 0) {\n            value >>= 128;\n            result += 128;\n        }\n        if (value >> 64 > 0) {\n            value >>= 64;\n            result += 64;\n        }\n        if (value >> 32 > 0) {\n            value >>= 32;\n            result += 32;\n        }\n        if (value >> 16 > 0) {\n            value >>= 16;\n            result += 16;\n        }\n        if (value >> 8 > 0) {\n            value >>= 8;\n            result += 8;\n        }\n        if (value >> 4 > 0) {\n            value >>= 4;\n            result += 4;\n        }\n        if (value >> 2 > 0) {\n            value >>= 2;\n            result += 2;\n        }\n        if (value >> 1 > 0) {\n            result += 1;\n        }\n    }\n    return result;\n}\n```\n