Linked Questions

Popular Questions

How can I put the LSB of a 16-bit value to MSB in C?

Asked by At

Doing a Booth's algorithm for class and I'm using bitwise operation. I'm trying to figure out how to place the LSB of a value prior to shiftng to the MSB of the value after it's been binary shifted, if that's actually possible?

This is the current loop:

for (int i = 0; i < SIZE; i++) {
    if (i == 0) {
        q_minus_one = 0;
        if (a_q & 1) {
            q0 = 1;
        } else {
            q0 = 0;
        }
    } else {
        if (a_q & 1) {
            q_minus_one = 1;
        } else {
            q_minus_one = 0;
        }
        if ((a_q >> 1) & 1) {
            q0 = 1;
        } else {
            q0 = 0;
        }
    }
    if (!(q0 ^ q_minus_one)) {
        printf("1");
    } else if (!(q0 ^ 1) ^ q_minus_one) {        //10
        printf("2");
        a_q-=(m << SIZE);
    } else if (!(q0 ^ 0) ^ q_minus_one) {        //01
        printf("3");
        a_q+=(m << SIZE);
    }
    a_q >>= 1;
}

Related Questions