Skip to content

IntToU64

IntToU64

Description

Convert an integer to u64.

Aborts if the integer does not fit in 64 bits.

Parameters

Name Direction Description
value in Integer to convert

Usage example (from documentation)

  u64 small = IntToU64(&value);

Returns

The numeric value as u64.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    u64 IntToU64(Int *value) {
        ValidateInt(value);
        }
    
        u64 lhs_value = IntToU64(lhs);
    
        if (lhs_value < rhs) {
        }
    
        MISRA_PRIV_IntPowU64(result, base, IntToU64(exponent));
    }
    
        IntDivMod(quotient, &remainder, dividend, &divisor_value);
        rem = IntToU64(&remainder);
    
        IntDeinit(&divisor_value);
    
        bool result = IntBitLength(&value) == 4;
        result      = result && (IntToU64(&value) == 13);
        result      = result && (strcmp(text.data, "1101") == 0);
        Str text  = IntToBinary(&value);
    
        bool result = IntToU64(&value) == 11;
        result      = result && (strcmp(text.data, "1011") == 0);
        Str text  = IntToStrRadix(&value, 36, false);
    
        bool result = IntToU64(&value) == 1295;
        result      = result && (strcmp(text.data, "zz") == 0);
        bool result = IntBitLength(&zero) == 0;
        result      = result && IntIsZero(&zero);
        result      = result && (IntToU64(&zero) == 0);
        result      = result && (strcmp(text.data, "0") == 0);
        Int value = IntFromBinary("0b1010_0011");
    
        bool result = IntToU64(&value) == 163;
        result      = result && (IntBitLength(&value) == 8);
        Str text  = IntToOctStr(&value);
    
        bool result = IntToU64(&value) == 493;
        result      = result && (strcmp(text.data, "755") == 0);
    
    bool test_int_to_u64_overflow(void) {
        WriteFmt("Testing IntToU64 overflow handling\n");
    
        Int value = IntFrom(1);
        Int value = IntFrom(1);
        IntShiftLeft(&value, 64);
        IntToU64(&value);
    
        return false;
        IntShiftLeft(&value, 4);
    
        bool result = IntToU64(&value) == 48;
        result      = result && (IntBitLength(&value) == 6);
        IntShiftRight(&value, 4);
    
        bool result = IntToU64(&value) == 3;
        result      = result && (IntBitLength(&value) == 2);
        text = IntToBinary(&result_value);
    
        bool result = IntToU64(&result_value) == 256;
        result      = result && (strcmp(text.data, "100000000") == 0);
    
        IntAdd(&result_value, &base, rhs);
        bool result = IntToU64(&result_value) == 42;
    
        IntAdd(&result_value, &base, 2);
    
        IntAdd(&result_value, &base, 2);
        result = result && (IntToU64(&result_value) == 42);
    
        IntAdd(&result_value, &base, -2);
    
        IntAdd(&result_value, &base, -2);
        result = result && (IntToU64(&result_value) == 38);
    
        IntAdd(&result_value, &huge, 10);
    
        bool result = IntSub(&result_value, &a, &b);
        result      = result && (IntToU64(&result_value) == 255);
    
        IntDeinit(&a);
    
        bool result = IntSub(&result_value, &base, rhs);
        result      = result && (IntToU64(&result_value) == 38);
    
        result = result && IntSub(&result_value, &base, 2u);
    
        result = result && IntSub(&result_value, &base, 2u);
        result = result && (IntToU64(&result_value) == 38);
    
        result = result && IntSub(&result_value, &base, -2);
    
        result = result && IntSub(&result_value, &base, -2);
        result = result && (IntToU64(&result_value) == 42);
    
        result = result && IntSub(&result_value, &huge, 90);
    
        result = result && !IntSub(&preserved, &base, 50);
        result = result && (IntToU64(&preserved) == 99);
    
        IntDeinit(&base);
    
        bool result = !IntSub(&result_value, &a, &b);
        result      = result && (IntToU64(&result_value) == 99);
    
        IntDeinit(&a);
        IntMul(&result_value, &a, &b);
    
        bool result = IntToU64(&result_value) == 126;
    
        IntDeinit(&a);
    
        bool result = IntIsZero(&result_value);
        result      = result && (IntToU64(&result_value) == 0);
    
        IntDeinit(&a);
        IntSquare(&result_value, &value);
    
        bool result = IntToU64(&result_value) == 152399025;
    
        IntDeinit(&value);
    
        bool result = strcmp(qtext.data, "127275040218913071") == 0;
        result      = result && (IntToU64(&remainder) == 3);
    
        StrDeinit(&qtext);
        IntDiv(&result_value, &dividend, 10u);
    
        bool result = IntToU64(&result_value) == 12;
    
        IntDeinit(&dividend);
    
        bool result = !IntDivExact(&result_value, &dividend, &divisor);
        result      = result && (IntToU64(&result_value) == 99);
    
        IntDeinit(&dividend);
    
        bool result = strcmp(text.data, "127275040218913071") == 0;
        result      = result && (IntToU64(&remainder) == 3);
    
        IntDeinit(&dividend);
        IntMod(&result_value, &dividend, 10u);
    
        bool result = IntToU64(&result_value) == 6;
    
        IntDeinit(&dividend);
    
        IntDeinit(&value);
        bool result = IntToU64(&remainder) == 3;
        IntDeinit(&remainder);
        return result;
        IntGCD(&result_value, &a, &b);
    
        bool result = IntToU64(&result_value) == 6;
    
        IntDeinit(&a);
        IntLCM(&result_value, &a, &b);
    
        bool result = IntToU64(&result_value) == 42;
    
        IntDeinit(&a);
        IntRoot(&result_value, &value, 4);
    
        bool result = IntToU64(&result_value) == 8;
    
        IntDeinit(&value);
        IntRootRem(&root, &remainder, &value, 3);
    
        bool result = IntToU64(&root) == 5;
        result      = result && (IntToU64(&remainder) == 75);
    
        bool result = IntToU64(&root) == 5;
        result      = result && (IntToU64(&remainder) == 75);
    
        IntDeinit(&value);
        IntSqrt(&result_value, &value);
    
        bool result = IntToU64(&result_value) == 14;
    
        IntDeinit(&value);
        IntSqrtRem(&root, &remainder, &value);
    
        bool result = IntToU64(&root) == 14;
        result      = result && (IntToU64(&remainder) == 4);
    
        bool result = IntToU64(&root) == 14;
        result      = result && (IntToU64(&remainder) == 4);
    
        IntDeinit(&value);
        IntSquareMod(&result_value, &value, &mod);
    
        bool result = IntToU64(&result_value) == 94;
    
        IntDeinit(&value);
        IntModAdd(&result_value, &a, &b, &m);
    
        bool result = IntToU64(&result_value) == 12;
    
        IntDeinit(&a);
        IntModSub(&result_value, &a, &b, &m);
    
        bool result = IntToU64(&result_value) == 9;
    
        IntDeinit(&a);
        IntModMul(&result_value, &a, &b, &m);
    
        bool result = IntToU64(&result_value) == 22;
    
        IntDeinit(&a);
    
        bool result = IntModDiv(&result_value, &a, &b, &m);
        result      = result && (IntToU64(&result_value) == 12);
    
        IntModMul(&check, &result_value, &b, &m);
        IntPowMod(&result_value, &base, 20u, &mod);
    
        bool result = IntToU64(&result_value) == 3;
    
        IntDeinit(&base);
        IntPowMod(&result_value, &base, &exp, &mod);
    
        bool result = IntToU64(&result_value) == 445;
    
        IntDeinit(&base);
    
        bool result = IntModInv(&result_value, &value, &mod);
        result      = result && (IntToU64(&result_value) == 4);
    
        IntModMul(&check, &value, &result_value, &mod);
    
        IntModMul(&check, &value, &result_value, &mod);
        result = result && (IntToU64(&check) == 1);
    
        IntDeinit(&value);
    
        bool result = !IntModInv(&result_value, &value, &mod);
        result      = result && (IntToU64(&result_value) == 99);
    
        IntDeinit(&value);
    
        bool result = IntEQ(&clone, &original);
        result      = result && (IntToU64(&clone) == 11);
    
        IntShiftLeft(&original, 1);
    
        result = result && !IntEQ(&clone, &original);
        result = result && (IntToU64(&clone) == 11);
        result = result && (IntToU64(&original) == 22);
        result = result && !IntEQ(&clone, &original);
        result = result && (IntToU64(&clone) == 11);
        result = result && (IntToU64(&original) == 22);
    
        IntDeinit(&original);
Last updated on