Skip to content

IntToHexStr

Description

Convert an integer to a hexadecimal string.

Parameters

Name Direction Description
value in Integer to convert.

Success

Returns a Str holding the base-16 textual form of value with lowercase letters, bound to value’s allocator. value is not modified.

Failure

Returns an empty Str bound to value’s allocator when the underlying IntToStrRadix fails (intermediate allocation failure). The caller cannot distinguish that from a true empty result; use IntTryToStrRadix directly when failure detection is required.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    Str IntToHexStr(const Int *value) {
        return IntToStrRadix(value, 16, false);
    }
        Int value   = IntFromBytesLE(bytes, sizeof(bytes), ALLOCATOR_OF(&alloc));
        u64 written = IntToBytesLE(&value, out, sizeof(out));
        Str text    = IntToHexStr(&value);
    
        bool result = written == 4;
        Int value   = IntFromBytesBE(bytes, sizeof(bytes), ALLOCATOR_OF(&alloc));
        u64 written = IntToBytesBE(&value, out, sizeof(out));
        Str text    = IntToHexStr(&value);
    
        bool result = written == 4;
        Zstr hex   = "deadbeefcafebabe1234";
        Int  value = IntFromHexStr(hex, ALLOCATOR_OF(&alloc));
        Str  text  = IntToHexStr(&value);
    
        bool result = ZstrCompare(StrBegin(&text), hex) == 0;
        z = "deadbeefcafebabe1234";
        StrReadFmt(z, "{x}", hex);
        hex_text = IntToHexStr(&hex);
        success  = success && (ZstrCompare(StrBegin(&hex_text), "deadbeefcafebabe1234") == 0);
Last updated on