IntFromBinary
Description
Compatibility wrapper for IntTryFromBinary(...).
Success
Returns Parsed integer value, or zero on failure.
Failure
Returns a zero-initialised Int on a non-binary character, an empty digit run, or an allocation failure. Use IntTryFromBinary(...) when explicit failure propagation is required.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Int.Access.c:24:
DefaultAllocator alloc = DefaultAllocatorInit();
Int value = IntFromBinary("00101000", &alloc.base);
bool result = IntBitLength(&value) == 6;- In
Int.Access.c:38:
DefaultAllocator alloc = DefaultAllocatorInit();
Int value = IntFromBinary("0001001000110100", &alloc.base);
bool result = IntByteLength(&value) == 2;- In
Int.Access.c:140:
DefaultAllocator alloc = DefaultAllocatorInit();
Int value = IntFromBinary("1010000", &alloc.base);
Int zero = IntInit(&alloc.base); DefaultAllocator alloc = DefaultAllocatorInit();
Int value = IntFromBinary("001011", ALLOCATOR_OF(&alloc));
Str text = IntToBinary(&value); DefaultAllocator alloc = DefaultAllocatorInit();
Int lhs = IntFromBinary("0001011", ALLOCATOR_OF(&alloc));
Int rhs = IntFrom(11, ALLOCATOR_OF(&alloc)); DefaultAllocator alloc = DefaultAllocatorInit();
Int zero = IntFromBinary("0", ALLOCATOR_OF(&alloc));
Str text = IntToBinary(&zero);
bool error = true; DefaultAllocator alloc = DefaultAllocatorInit();
Int value = IntFromBinary("0b1010_0011", ALLOCATOR_OF(&alloc));
bool result = IntToU64(&value) == 163;
bool test_int_from_binary_invalid_digit(void) {
WriteFmt("Testing IntFromBinary invalid digit handling\n");
DefaultAllocator alloc = DefaultAllocatorInit(); DefaultAllocator alloc = DefaultAllocatorInit();
Int parsed = IntFromBinary("10a1", ALLOCATOR_OF(&alloc));
Int value = IntInit(ALLOCATOR_OF(&alloc));
bool result = !IntTryFromBinary(&value, "10a1");
bool test_int_from_binary_null(void) {
WriteFmt("Testing IntFromBinary NULL handling\n");
DefaultAllocator alloc = DefaultAllocatorInit(); DefaultAllocator alloc = DefaultAllocatorInit();
Int parsed = IntFromBinary((Zstr)NULL, ALLOCATOR_OF(&alloc));
Int value = IntInit(ALLOCATOR_OF(&alloc));
bool result = !IntTryFromBinary(&value, (Zstr)NULL);- In
Int.Type.c:34:
DefaultAllocator alloc = DefaultAllocatorInit();
Int value = IntFromBinary("101101", &alloc.base);
IntClear(&value);- In
Int.Type.c:51:
DefaultAllocator alloc = DefaultAllocatorInit();
Int original = IntFromBinary("1011", &alloc.base);
Int clone = IntClone(&original);- In
Io.Write.c:596:
Int big_dec = IntFromStr("123456789012345678901234567890", alloc_base);
Int hex_val = IntFromHexStr("deadbeefcafebabe1234", alloc_base);
Int bin_val = IntFromBinary("10100011", alloc_base);
Int oct_val = IntFrom(493, alloc_base);- In
Int.Compare.c:23:
Int a = IntFrom(41, &alloc.base);
Int b = IntFrom(42, &alloc.base);
Int c = IntFromBinary("000101010", &alloc.base);
bool result = IntCompare(&a, &b) < 0;- In
Int.Compare.c:43:
Int a = IntFrom(41, &alloc.base);
Int b = IntFrom(42, &alloc.base);
Int c = IntFromBinary("000101010", &alloc.base);
bool result = IntLT(&a, &b);- In
Int.Compare.c:67:
Int value = IntFrom(42, &alloc.base);
Int same = IntFromBinary("00101010", &alloc.base);
Int big = IntFrom(1, &alloc.base);- In
Int.Compare.c:98:
Int a = IntFrom(42u, &alloc.base);
Int b = IntFromBinary("101010", &alloc.base);
Int c = IntFrom(0u, &alloc.base);
Int d = IntFrom(0u, &alloc.base);- In
Int.Math.c:84:
DefaultAllocator alloc = DefaultAllocatorInit();
Int value = IntFromBinary("110000", &alloc.base);
IntShiftRight(&value, 4);
Last updated on