Skip to content

IntByteLength

Description

Number of bytes required to store the integer (ceil of bit length over eight).

Parameters

Name Direction Description
value in Integer to inspect.

Success

Returns the byte length as a u64. Returns 0 when value is zero. The integer is not modified.

Failure

Function cannot fail.

Usage example (Cross-references)

Usage examples (Cross-references)
    
        if (fmt_info->flags & FMT_FLAG_CHAR) {
            u64 byte_len = IntByteLength(value);
    
            if (byte_len == 0) {
    }
    
    u64 IntByteLength(const Int *value) {
        u64 bits = IntBitLength(value);
        return bits == 0 ? 0 : CEIL_DIV(bits, 8u);
        }
    
        u64 bytes_needed  = IntByteLength(value);
        u64 bytes_to_copy = MIN2(bytes_needed, max_len);
        }
    
        u64 bytes_needed  = IntByteLength(value);
        u64 bytes_to_copy = MIN2(bytes_needed, max_len);
    
    bool test_int_byte_length(void) {
        WriteFmt("Testing IntByteLength\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Int value = IntFromBinary("0001001000110100", &alloc.base);
    
        bool result = IntByteLength(&value) == 2;
    
        IntDeinit(&value);
Last updated on