BitVecFromBytes
Description
Build a bitvector from raw bytes using an explicit allocator.
Parameters
| Name | Direction | Description |
|---|---|---|
bytes |
in | Source byte buffer. |
bit_len |
in | Number of bits to read from bytes. |
alloc |
in | Allocator to bind to the returned bitvector. |
Success
Returns initialized bitvector.
Failure
Returns an empty bitvector if allocation fails.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Convert.c:141:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecFromBytes\n");
// Create byte array
- In
Convert.c:300:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecFromBytes with zero bit length\n");
u8 dummy_bytes[1] = {0xFF};- In
Convert.c:303:
u8 dummy_bytes[1] = {0xFF};
BitVec empty_bv = BitVecFromBytes(dummy_bytes, 0, ALLOCATOR_OF(&alloc));
bool result = (BitVecLen(&empty_bv) == 0);
BitVecDeinit(&empty_bv);- In
Convert.c:398:
// Test bytes to bitvec with 0 bits (should return empty bitvector)
u8 empty_bytes[1] = {0x05};
BitVec bv2 = BitVecFromBytes(empty_bytes, 0, ALLOCATOR_OF(&alloc)); // 0 bits
result = result && (BitVecLen(&bv2) == 0);
BitVecDeinit(&bv2);- In
Convert.c:404:
// Test single byte
u8 single_byte[1] = {0xFF};
BitVec bv3 = BitVecFromBytes(single_byte, 8, ALLOCATOR_OF(&alloc)); // 8 bits from 1 byte
result = result && (BitVecLen(&bv3) == 8);
BitVecDeinit(&bv3);- In
Convert.c:488:
for (size i = 0; i < sizeof(test_bytes); i++) {
BitVec bv = BitVecFromBytes(&test_bytes[i], 8, ALLOCATOR_OF(&alloc));
u8 recovered_byte = 0;
u64 written = BitVecToBytes(&bv, &recovered_byte, 1);- In
Convert.c:609:
BitVec bv1 = BitVecFromStr("11010110", ALLOCATOR_OF(&alloc));
BitVec bv2 = BitVecFromInteger(0xD6, 8, ALLOCATOR_OF(&alloc));
BitVec bv3 = BitVecFromBytes((u8[]) {0xD6}, 8, ALLOCATOR_OF(&alloc));
Str str1 = BitVecToStr(&bv1);- In
Convert.c:674:
// Test round-trip from bytes
BitVec recovered_bv = BitVecFromBytes(large_bytes, 1000, ALLOCATOR_OF(&alloc));
result = result && (BitVecLen(&recovered_bv) == 1000);- In
Convert.c:785:
// Test NULL bytes - should abort
BitVecFromBytes(NULL, 8, ALLOCATOR_OF(&alloc)); // NULL bytes, 8 bits
DefaultAllocatorDeinit(&alloc);
Last updated on