Skip to content

IntLog2

IntLog2

Description

Compute floor(log2(value)).

Undefined for zero. This function aborts when called on zero.

Parameters

Name Direction Description
value in Integer to inspect

Usage example (from documentation)

  u64 msb = IntLog2(&value);

Returns

Index of the highest set bit.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    u64 IntLog2(Int *value) {
        ValidateInt(value);
        }
    
        u64 max_degree = IntLog2(value);
    
        for (u64 degree = 2; degree <= max_degree; degree++) {
    
    bool test_int_log2(void) {
        WriteFmt("Testing IntLog2\n");
    
        Int value = IntFrom(1025);
        Int value = IntFrom(1025);
    
        bool result = IntLog2(&value) == 10;
    
        IntDeinit(&value);
    
    bool test_int_log2_zero(void) {
        WriteFmt("Testing IntLog2 zero handling\n");
    
        Int value = IntInit();
        Int value = IntInit();
    
        IntLog2(&value);
        return false;
    }
Last updated on