Skip to content
IntFromBytesLE

IntFromBytesLE

Description

Create an integer from little-endian bytes.

Parameters

Name Direction Description
bytes in Source byte buffer holding the magnitude in little-endian order (least significant byte first). May be NULL when len == 0.
len in Number of bytes to read from bytes.
alloc in Allocator to bind to the returned integer.

Success

Returns a normalised Int holding the unsigned magnitude packed in bytes. bytes is not modified.

Failure

Returns a zero-initialised Int bound to alloc when the underlying bit-vector allocation fails. The caller cannot distinguish that from a true zero result. LOG_FATAL when bytes is NULL and len != 0.

Usage example (Cross-references)

Usage examples (Cross-references)
        u8  bytes[] = {0x34, 0x12, 0xEF, 0xCD};
        u8  out[4]  = {0};
        Int value   = IntFromBytesLE(bytes, sizeof(bytes), ALLOCATOR_OF(&alloc));
        u64 written = IntToBytesLE(&value, out, sizeof(out));
        Str text    = IntToHexStr(&value);
    
    bool test_int_from_bytes_le_null(void) {
        WriteFmt("Testing IntFromBytesLE NULL handling\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        IntFromBytesLE(NULL, 1, ALLOCATOR_OF(&alloc));
        DefaultAllocatorDeinit(&alloc);
        return false;
Last updated on