Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Someone help with my bit division problems please

+2 votes
asked Jan 30, 2018 by Lee Shallis (360 points)
edited Jan 30, 2018 by Lee Shallis

I tried everything I could think of and still can’t get it to work, here's the code:


zuv_t* __zuvDiv( zuv_t *num, zuv_t const *val, zuv_t *rem ) {
    if ( !_zuvRlNum(num) || !_zuvRlNum(rem) ||
        num->size != rem->size || num->bits > (USHRT_MAX * CHAR_BIT) )
        return NULL;
    memcpy( rem->buff, num->buff, num->size );
    memset( num->buff, 0, num->size );
    if ( !_zuvRlNum(val) ) {
        memset( rem->buff, 0, rem->size );
        return num;
    }
    if ( _zuvLth( rem, val ) )
        return num;
    _zbit_t n = _zuvBwCmp( rem, 0 ), nbeg = _CalcZbit( num->zero );
    zuv_t sec = *rem;
    sec.bits = 1;
    sec.zero = n.num;
    while ( sec.bits < num->bits && _zuvMeq( rem, val ) ) {
        _DecZbit( n, nbeg, break )
        if ( _zuvMeq( &sec, val ) ) {
            _zuvSub( &sec, val );
            num->buff[n.pos] |= n.bit;
        }
        sec.zero--;
        sec.bits++;
        n.bit >>= 1;
    }
    return num;
}

And here's the results:


2310 one = 00000111010110111100110100010101u, 123456789u
2311 two = 00000000000000000000000001110000u, 7u
2312 (val1 /= val2) = 00000001000011010001110101001100u
2313 (num1 /= num2) = 00000001000111111111111111111111u
2320 one = 00000111010110111100110100010101u, 123456789u
2321 two = 00000000000000000000000011010000u, 13u
2322 (val1 /= val3) = 00000000100100001110100001100100u
2323 (num1 /= num3) = 00000000100100011111111111111111u
2330 one = 00000000000000000000000000000111u, 7u
2331 two = 00000000000000000000000011010000u, 13u
2332 (val2 /= val3) = 00000000000000000000000000000000u
2333 (num2 /= num3) = 00000000000000000000000000000000u

Edit: Formatting had been broken so changed it (the formatting) to something easier to read

Edit 2: Found I had been referencing num in places I should have been referencing rem, corrected that and updated above code & results

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...