Problem related to bitwise

how do i efficiently find bitwise OR of all elements in a given range[l,r].
someone please help me out
I am not able to understand the code given in stack overflow . someone please explain me the logic Here is the code below

unsigned int bitwiseor(unsigned int a, unsigned int b){
    if (a==b)
        return a;
    unsigned final = 0;
    unsigned rev = 0;
    while(b){
        final*=2;
        if (a%2==1 || a != b)
            final++;
        a/=2;
        b/=2;
    }
    while(final){
        rev *= 2;
        rev += final % 2;
        final/=2;
    }
    return rev;
}

Also how this problem is a solution to the october cook off question DOR ? how is it related ??

1 Like