0
I have problem with For which types of number does while loop iterates for?(I know the function of &)while (a & a-1).
Bitwise operation
7 Respuestas
0
in your specific case
while(a & a-1) should work as long as "a" is a number (i forget if bitwise operators work on fixed/floating-point numbers)
0
It won't work for a=8
0
Shakkir Moulana the code will work it's just that the while loop won't ever execute because
8 (0000 1000) &
7 (0000 0111) =
0 (0000 0000) which equates to false
apologies if i misunderstood the question i thought it was about the code working not the loop
0
Can you mention for which types of numbers would the loop iterates
0
Shakkir Moulana the loop would run under numbers which keep at least one "1" in the same place when they are subtracted from by 1. examples:
6 (0000 0110) &
5 (0000 0101) =
4 (0000 0100) which equates to true iirc
7 (0000 0111) &
6 (0000 0110) =
6 (0000 0110) which is also true
0
is there any pattern while observing decimal numbers (not by observing binary)
0
Shakkir Moulana nope, as these are bitwise operators they strictly work with binary representations of numbers