Skip to content
BitVecTryFromInteger

BitVecTryFromInteger

Description

Build a bitvector from an integer using an explicit allocator.

Parameters

Name Direction Description
out out Destination bitvector.
value in Integer value to convert.
bits in Number of bits to emit.
alloc in Allocator to bind to the destination bitvector.

Success

Returns true and initializes out.

Failure

Returns false if allocation fails.

Usage example (Cross-references)

Usage examples (Cross-references)
        }
    
        if (!BitVecTryFromInteger(INT_BITS(out), value, bits, alloc)) {
            IntDeinit(out);
            *out = IntInit(alloc);
        u64    value = 11; // 1011 in binary
        BitVec bv;
        bool   ok = BitVecTryFromInteger(&bv, value, 4, ALLOCATOR_OF(&alloc));
    
        // Check result
        // Test with zero
        BitVec zero_bv;
        result = result && BitVecTryFromInteger(&zero_bv, 0, 8, ALLOCATOR_OF(&alloc));
        result = result && (BitVecLen(&zero_bv) == 8);
    
        BitVec bv;
        bool   ok = BitVecTryFromInteger(&bv, 0xFFu, 100, ALLOCATOR_OF(&alloc));
    
        bool result = ok && (BitVecLen(&bv) == 64);
Last updated on