Skip to content
IntIsPowerOfTwo

IntIsPowerOfTwo

IntIsPowerOfTwo

Description

Test whether the integer is a power of two.

Parameters

Name Direction Description
value in Integer to test

Usage example (from documentation)

  bool pow2 = IntIsPowerOfTwo(&value);

Returns

true when exactly one bit is set and the value is non-zero.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    bool IntIsPowerOfTwo(Int *value) {
        ValidateInt(value);
    
    bool test_int_is_power_of_two(void) {
        WriteFmt("Testing IntIsPowerOfTwo\n");
    
        Int one   = IntFrom(1);
        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