Skip to content
IntTrailingZeroCount

IntTrailingZeroCount

Description

Number of trailing zero bits (equivalent to the largest power of two that divides the value).

Parameters

Name Direction Description
value in Integer to inspect.

Success

Returns the trailing-zero count as a u64. Returns 0 when value is zero. The integer is not modified.

Failure

Function cannot fail.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    u64 IntTrailingZeroCount(const Int *value) {
        ValidateInt(value);
        ValidateInt(value);
    
        return !IntIsZero(value) && IntBitLength(value) == IntTrailingZeroCount(value) + 1;
    }
    
    bool test_int_trailing_zero_count(void) {
        WriteFmt("Testing IntTrailingZeroCount\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Int zero  = IntInit(&alloc.base);
    
        bool result = IntTrailingZeroCount(&value) == 4;
        result      = result && (IntTrailingZeroCount(&zero) == 0);
    
        bool result = IntTrailingZeroCount(&value) == 4;
        result      = result && (IntTrailingZeroCount(&zero) == 0);
    
        IntDeinit(&value);
Last updated on