Skip to content

IntByteLength

IntByteLength

Description

Get the minimum number of bytes needed to encode an integer.

Parameters

Name Direction Description
value in Integer to inspect

Usage example (from documentation)

  u64 bytes = IntByteLength(&value);

Returns

Number of bytes required to represent the value, or 0 for zero.

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(Int *value) {
        u64 bits = IntBitLength(value);
        return bits == 0 ? 0 : (bits + 7) / 8;
        }
    
        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");
    
        Int value = IntFromBinary("0001001000110100");
        Int value = IntFromBinary("0001001000110100");
    
        bool result = IntByteLength(&value) == 2;
    
        IntDeinit(&value);
Last updated on