Skip to content
IntIsPowerOfTwo

IntIsPowerOfTwo

Description

Test whether the integer is a power of two (1, 2, 4, 8, …).

Parameters

Name Direction Description
value in Integer to inspect.

Success

Returns true when the integer is a power of two.

Failure

Returns false for zero or non-power-of-two values.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    bool IntIsPowerOfTwo(const Int *value) {
        ValidateInt(value);
    
    bool test_int_is_power_of_two(void) {
        WriteFmt("Testing IntIsPowerOfTwo\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        IntShiftLeft(&power, 20);
    
        bool result = IntIsPowerOfTwo(&one);
        result      = result && IntIsPowerOfTwo(&power);
        result      = result && !IntIsPowerOfTwo(&other);
    
        bool result = IntIsPowerOfTwo(&one);
        result      = result && IntIsPowerOfTwo(&power);
        result      = result && !IntIsPowerOfTwo(&other);
        result      = result && !IntIsPowerOfTwo(&zero);
        bool result = IntIsPowerOfTwo(&one);
        result      = result && IntIsPowerOfTwo(&power);
        result      = result && !IntIsPowerOfTwo(&other);
        result      = result && !IntIsPowerOfTwo(&zero);
        result      = result && IntIsPowerOfTwo(&power);
        result      = result && !IntIsPowerOfTwo(&other);
        result      = result && !IntIsPowerOfTwo(&zero);
    
        IntDeinit(&one);
Last updated on