Skip to content

IntBitLength

IntBitLength

Description

Get the number of significant bits in an integer.

Parameters

Name Direction Description
value in Integer to inspect

Usage example (from documentation)

  u64 bits = IntBitLength(&value);

Returns

Number of significant bits, or 0 for zero.

Usage example (Cross-references)

Usage examples (Cross-references)
    static bool int_is_one(Int *value) {
        ValidateInt(value);
        return IntBitLength(value) == 1 && BitVecGet(INT_BITS(value), 0);
    }
    }
    
    u64 IntBitLength(Int *value) {
        return int_significant_bits(value);
    }
    
    u64 IntByteLength(Int *value) {
        u64 bits = IntBitLength(value);
        return bits == 0 ? 0 : (bits + 7) / 8;
    }
        }
    
        return IntBitLength(value) - 1;
    }
    
    bool IntIsZero(Int *value) {
        return IntBitLength(value) == 0;
    }
    bool IntFitsU64(Int *value) {
        ValidateInt(value);
        return IntBitLength(value) <= 64;
    }
        ValidateInt(value);
    
        return !IntIsZero(value) && IntBitLength(value) == IntTrailingZeroCount(value) + 1;
    }
        ValidateInt(rhs);
    
        u64 lhs_bits = IntBitLength(lhs);
        u64 rhs_bits = IntBitLength(rhs);
    
        u64 lhs_bits = IntBitLength(lhs);
        u64 rhs_bits = IntBitLength(rhs);
    
        if (lhs_bits < rhs_bits) {
        ValidateInt(lhs);
    
        if (IntBitLength(lhs) > 64) {
            return 1;
        }
        ValidateInt(value);
    
        u64 bits = IntBitLength(value);
    
        if (positions == 0) {
        ValidateInt(value);
    
        u64 bits = IntBitLength(value);
    
        if (positions == 0) {
        ValidateInt(b);
    
        u64 a_bits   = IntBitLength(a);
        u64 b_bits   = IntBitLength(b);
        u64 max_bits = MAX2(a_bits, b_bits);
    
        u64 a_bits   = IntBitLength(a);
        u64 b_bits   = IntBitLength(b);
        u64 max_bits = MAX2(a_bits, b_bits);
        Int temp     = int_init_with_capacity(max_bits + 1);
        }
    
        u64 a_bits = IntBitLength(a);
        u64 b_bits = IntBitLength(b);
        Int temp   = int_init_with_capacity(a_bits);
    
        u64 a_bits = IntBitLength(a);
        u64 b_bits = IntBitLength(b);
        Int temp   = int_init_with_capacity(a_bits);
        bool borrow = false;
        ValidateInt(b);
    
        u64 b_bits = IntBitLength(b);
        Int acc    = IntInit();
    
        if (IntCompare(&normalized_dividend, &normalized_divisor) >= 0) {
            u64 dividend_bits = IntBitLength(&normalized_dividend);
            u64 divisor_bits  = IntBitLength(&normalized_divisor);
        if (IntCompare(&normalized_dividend, &normalized_divisor) >= 0) {
            u64 dividend_bits = IntBitLength(&normalized_dividend);
            u64 divisor_bits  = IntBitLength(&normalized_divisor);
    
            q = int_init_with_capacity(dividend_bits - divisor_bits + 1);
                    r = next;
    
                    if (IntBitLength(&q) < bit + 1) {
                        BitVecResize(INT_BITS(&q), bit + 1);
                    }
        }
    
        u64 bits       = IntBitLength(value);
        u64 high_shift = bits / degree;
        Int low        = IntInit();
        ValidateInt(value);
    
        if (IntIsZero(value) || IntBitLength(value) == 1) {
            return true;
        }
        Str text  = IntToBinary(&value);
    
        bool result = IntBitLength(&value) == 4;
        result      = result && (IntToU64(&value) == 13);
        result      = result && (strcmp(text.data, "1101") == 0);
        Str text = IntToBinary(&zero);
    
        bool result = IntBitLength(&zero) == 0;
        result      = result && IntIsZero(&zero);
        result      = result && (IntToU64(&zero) == 0);
    
        bool result = IntToU64(&value) == 163;
        result      = result && (IntBitLength(&value) == 8);
    
        IntDeinit(&value);
    
    bool test_int_bit_length(void) {
        WriteFmt("Testing IntBitLength\n");
    
        Int value = IntFromBinary("00101000");
        Int value = IntFromBinary("00101000");
    
        bool result = IntBitLength(&value) == 6;
    
        IntDeinit(&value);
    
        bool result = IntToU64(&value) == 48;
        result      = result && (IntBitLength(&value) == 6);
    
        IntDeinit(&value);
    
        bool result = IntToU64(&value) == 3;
        result      = result && (IntBitLength(&value) == 2);
    
        IntDeinit(&value);
    
        bool result = IntIsZero(&value);
        result      = result && (IntBitLength(&value) == 0);
    
        IntDeinit(&value);
    
        bool result = IntIsZero(&value);
        result      = result && (IntBitLength(&value) == 0);
    
        IntDeinit(&value);
Last updated on