Skip to content

IntShiftRight

Description

Shift an integer right by the given number of bit positions.

Parameters

Name Direction Description
value in Integer to modify
positions in Number of low bits to discard

Usage example (from documentation)

  IntShiftRight(&value, 1);

Success

Returns true. *value has been shifted in place.

Failure

Returns false on allocator OOM while trimming the significand. *value is left untouched.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    bool IntShiftRight(Int *value, u64 positions) {
        ValidateInt(value);
            int cmp     = 0;
    
            if (!int_add(&sum, &low, &high) || !IntShiftRight(&sum, 1)) {
                IntDeinit(&sum);
                IntDeinit(&mid);
                u64 n_mod_8 = 0;
    
                if (!IntShiftRight(&aa, 1)) {
                    IntDeinit(&aa);
                    IntDeinit(&nn);
            }
    
            if (!IntShiftRight(&exp, 1)) {
                IntDeinit(&acc);
                IntDeinit(&base_mod);
            Int root     = IntInit(IntAllocator(result));
    
            if (!IntTryClone(&exponent, modulus) || !int_add_u64(&exponent, &exponent, 1) || !IntShiftRight(&exponent, 2) ||
                !int_pow_mod(&root, &a, &exponent, modulus)) {
                IntDeinit(&exponent);
            }
            while (IntIsEven(&q)) {
                if (!IntShiftRight(&q, 1)) {
                    IntDeinit(&q);
                    IntDeinit(&z);
            }
    
            if (!IntTryClone(&exponent, &q) || !int_add_u64(&exponent, &exponent, 1) || !IntShiftRight(&exponent, 1) ||
                !int_pow_mod(&r, &a, &exponent, modulus)) {
                IntDeinit(&q);
    
            while (IntIsEven(&d)) {
                if (!IntShiftRight(&d, 1)) {
                    IntDeinit(&d);
                    IntDeinit(&n_minus_one);
    
    bool test_int_shift_right_shrinks(void) {
        WriteFmt("Testing IntShiftRight\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Int value = IntFromBinary("110000", &alloc.base);
    
        IntShiftRight(&value, 4);
    
        bool result = IntToU64(&value) == 3;
Last updated on