Meaning of the instruction >>=
Hello,
I do not know what this instruction does:
temp >>= 15;
The context where I found is:
Code:
int my_random(int max) { // Return Random Int Between 0 and max
unsigned long temp;
temp = (unsigned long) rand();
temp *= (unsigned long) max;
temp >>= 15;
return (int) temp;
}
Help!
Right shift by 15 times contents of tmp
Quote:
Originally Posted by
stevesmithx
">>=" is a bitwise assignment operator.
means right shift temp by 15 and assign it back to temp.
Go throgh following code
Code:
int main(int argc, char* argv[])
{
int tmp = 0xffff;
printf("%d", tmp = tmp >> 15); //tmp >>= 15 same as tmp = tmp >> 15
return 0;
}
Ouput is 1