IntToStrRadix
Description
Convert an integer to text in the given radix. Two forms via argument count:
IntToStrRadix(value, radix, uppercase)-value’s allocator.IntToStrRadix(value, radix, uppercase, alloc)- explicit allocator.
Success
Returns a Str holding the textual form of value in base radix.
Failure
Returns an empty Str bound to alloc when the underlying IntTryToStrRadix fails (unsupported radix or intermediate allocation failure); the caller cannot distinguish that from a true empty result, so callers that need to detect failure should use IntTryToStrRadix directly.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Int.c:914:
Str IntToBinary(const Int *value) {
return IntToStrRadix(value, 2, false);
}- In
Int.c:963:
Str IntToOctStr(const Int *value) {
return IntToStrRadix(value, 8, false);
}- In
Int.c:1000:
Str IntToHexStr(const Int *value) {
return IntToStrRadix(value, 16, false);
}- In
Convert.c:193:
Int value = IntFromStrRadix("zz", 36, ALLOCATOR_OF(&alloc));
Str text = IntToStrRadix(&value, 36, false);
bool result = IntToU64(&value) == 1295;- In
Convert.c:210:
Int value = IntFrom(0xBEEF, ALLOCATOR_OF(&alloc));
Str text = IntToStrRadix(&value, 16, true);
bool result = ZstrCompare(StrBegin(&text), "BEEF") == 0;- In
Convert.c:446:
bool test_int_to_str_radix_invalid_radix(void) {
WriteFmt("Testing IntToStrRadix invalid radix handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Convert.c:451:
Int value = IntFrom(255, ALLOCATOR_OF(&alloc));
Str text = IntToStrRadix(&value, 37, false);
bool result = StrLen(&text) == 0;- In
Convert.c:894:
Int big = IntFromStr("123456789012345678901234567890", &alloc.base);
Str dec_small = IntToStrRadix(&small, 10, false, &alloc.base);
Str hex_mid = IntToStrRadix(&mid, 16, false, &alloc.base);
Str hex_mid_u = IntToStrRadix(&mid, 16, true, &alloc.base);- In
Convert.c:895:
Str dec_small = IntToStrRadix(&small, 10, false, &alloc.base);
Str hex_mid = IntToStrRadix(&mid, 16, false, &alloc.base);
Str hex_mid_u = IntToStrRadix(&mid, 16, true, &alloc.base);
Str dec_big = IntToStrRadix(&big, 10, false, &alloc.base);- In
Convert.c:896:
Str dec_small = IntToStrRadix(&small, 10, false, &alloc.base);
Str hex_mid = IntToStrRadix(&mid, 16, false, &alloc.base);
Str hex_mid_u = IntToStrRadix(&mid, 16, true, &alloc.base);
Str dec_big = IntToStrRadix(&big, 10, false, &alloc.base);- In
Convert.c:897:
Str hex_mid = IntToStrRadix(&mid, 16, false, &alloc.base);
Str hex_mid_u = IntToStrRadix(&mid, 16, true, &alloc.base);
Str dec_big = IntToStrRadix(&big, 10, false, &alloc.base);
bool result = (ZstrCompare(StrBegin(&dec_small), "7") == 0);- In
Convert.c:927:
Int parsed_hex = IntFromStrRadix("deadbeef", 16, &alloc.base);
Str back_dec = IntToStrRadix(&parsed_dec, 10, false, &alloc.base);
Str back_hex = IntToStrRadix(&parsed_hex, 16, false, &alloc.base);- In
Convert.c:928:
Str back_dec = IntToStrRadix(&parsed_dec, 10, false, &alloc.base);
Str back_hex = IntToStrRadix(&parsed_hex, 16, false, &alloc.base);
bool result = (ZstrCompare(StrBegin(&back_dec), "987654321987654321") == 0);- In
Convert.c:1573:
// (1583/1584) and int_mod_u64 (1630).
Int v = IntFrom(1234567u, a);
Str s = IntToStrRadix(&v, 10, false, a);
bool ok = StrLen(&s) == 7;
u64 rem = 0;- In
Convert.c:1625:
Int value = IntFromStr("123456789012345678901234567890", alloc);
Str hex = IntToStrRadix(&value, 16, false, alloc);
Int parsed = IntFromStrRadix(&hex, 16, alloc);
Last updated on